EF7 - You're Owned not complex

February 20, 2023
dev ef

OK - the title is misleading, but weirdly true. no mo' complex!

In a painful move (because we've all been there) but one that seems pointless from where I am, the functionality that [ComplexType] provided in EF6 (and below? I haven't used EF since 3 or 4) has been renamed to [Owned].

From what I can tell, nothing else has changed. The functionality is the 100% the same. The documentation of the change is lame AF. I could not find a single reference. And in fact, I was only able to finally get this figured out by finding a EF7 preview 5 bug on GitHub where someone mentioned [Owned]. And that lead to the answer.

I find it interesting that there's no mention of the move from ComplexType to Owned as the attribute. You'd think there'd be some. The worst of it is that it continues to work. It's still a type in DataAnnotations and there's error or warnings. I added a GitHub doc's feedback.

And, FSAF I checked ChatGPT - could it be smarter than me? Would it be smart enough to figure it out? No. It gave the simple Complex attribute and then a much more complicated (but that would have worked) answer to use json. So, even Mr.Chat has not been able to read up on the change.

Owned Entity Types - EF Core | Microsoft Learn

public class Me
{
public string Name {get;set;}
public Address Home P{get;set;}
}

[Owned]
public class Address
{
public string StreetNumber {get;set;}
public string City {get;set}
}