Map column to child object in EF Core 3

c# ef-core-3.1 entity-framework-core sql-server

Question

Giving the sample below, is there any way to have Address in the same table as User without making use of table splitting or owned types (eg like EF6 complex types)? The generated SQL prevents me from using it and complex types does not seem to be supported in EF Core 3:

    public class User
    {
        public int Id { get; set; }

        public Address Address { get; set; }

        public string UserName { get; set; }
    }


    public class Address
    {
        public string StreetAddress { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public string ZipCode { get; set; }
    }

The only other options I see would be to map Address to its own table.

1
1
1/21/2020 3:37:48 PM

Accepted Answer

I will use a 1 to 0..1 relationship or include the properties in User directly.

Nevertheless, using Owned Types as a replacement for ComplexTypes like in EF 6 is horrible , if not completely useless from a SQL perspective, and I cannot see any reason for the joins. Maybe someone can clarify a proper justification for completness

0
1/22/2020 5:27:04 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow