Hello.
I've found incorrect complex types loading in EF Core Preview7 (in the Preview5 my code works normally).
I have some classes with an orders information:
```C#
public class OrderProfile
{
[Key]
public Guid Id { get; set; }
public int CargoClass { get; set; }
public Volume Volume { get; set; }
public float Weigth { get; set; }
public ICollection<int> AuxElements { get; set; }
public DateTime DeliveryDate { get; set; }
public GeoPoint StartPoint { get; set; }
public GeoPoint EndPoint { get; set; }
public ShortContact CargoSenderInfo { get; set; }
public ShortContact CargoReceiverInfo { get; set; }
public DateTime HandlingLoadTime { get; set; }
public DateTime HandlingUnloadTime { get; set; }
public int MinTemperature { get; set; }
public int MaxTemperature { get; set; }
public bool IsIsolated { get; set; }
public bool ByOwnTruck { get; set; }
//public ICollection<Guid> TrustedConveyors { get; set; }
public Guid OrderId { get; set; }
public Order Order { get; set; }
}
```C#
[Owned]
public class GeoPoint
{
public GeoPoint()
{
}
public GeoPoint(string address)
public GeoPoint(Location location)
{
Address = location.Address;
Latitude = location.Latitude;
Longitude = location.Longitude;
}
public double Latitude { get; set; }
public double Longitude { get; set; }
public string Address{ get; set; }
}
```C#
[Owned, ComplexType]
public class Volume
{
public float Length { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public float Cum { get; set; }
}
I have `OrderStoreDbContext `as derived class from `DbContext` with the property `public DbSet<OrderProfile> OrderProfiles { get; set; }`
So, I have correctly autogenerated migration:
```C#
modelBuilder.Entity("DatabaseServiceNew.Database.Order_information.OrderProfile", b =>
{
b.HasOne("DatabaseService.Database.Order_information.Order", "Order")
.WithOne("OrderProfile")
.HasForeignKey("DatabaseServiceNew.Database.Order_information.OrderProfile", "OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("DatabaseServiceNew.Database.Base_classes.Personality.ShortContact", "CargoReceiverInfo", b1 =>
{
b1.Property<Guid>("OrderProfileId");
b1.Property<string>("Name");
b1.Property<string>("PhoneNumber");
b1.HasKey("OrderProfileId");
b1.ToTable("OrderProfiles");
b1.WithOwner()
.HasForeignKey("OrderProfileId");
});
b.OwnsOne("DatabaseServiceNew.Database.Base_classes.Personality.ShortContact", "CargoSenderInfo", b1 =>
{
b1.Property<Guid>("OrderProfileId");
b1.Property<string>("Name");
b1.Property<string>("PhoneNumber");
b1.HasKey("OrderProfileId");
b1.ToTable("OrderProfiles");
b1.WithOwner()
.HasForeignKey("OrderProfileId");
});
b.OwnsOne("FoundationClasses.Technical_Classes.Volume", "Volume", b1 =>
{
b1.Property<Guid>("OrderProfileId");
b1.Property<float>("Cum");
b1.Property<float>("Height");
b1.Property<float>("Length");
b1.Property<float>("Width");
b1.HasKey("OrderProfileId");
b1.ToTable("OrderProfiles");
b1.WithOwner()
.HasForeignKey("OrderProfileId");
});
b.OwnsOne("WebFoundationClassesCore.Data_classes.GeoPoint", "EndPoint", b1 =>
{
b1.Property<Guid>("OrderProfileId");
b1.Property<string>("Address");
b1.Property<double>("Latitude");
b1.Property<double>("Longitude");
b1.HasKey("OrderProfileId");
b1.ToTable("OrderProfiles");
b1.WithOwner()
.HasForeignKey("OrderProfileId");
});
b.OwnsOne("WebFoundationClassesCore.Data_classes.GeoPoint", "StartPoint", b1 =>
{
b1.Property<Guid>("OrderProfileId");
b1.Property<string>("Address");
b1.Property<double>("Latitude");
b1.Property<double>("Longitude");
b1.HasKey("OrderProfileId");
b1.ToTable("OrderProfiles");
b1.WithOwner()
.HasForeignKey("OrderProfileId");
});
});
but neither request var orderProfiles = await orderDbContext.OrderProfiles.ToListAsync(); nor request var orderProfiles = await orderDbContext.OrderProfiles.Include(p => p.Volume).ToListAsync(); returns me valid information about Volumeor EndPoint/StartPoint, I always get null. Also CargoSenderInfo and CargoReceiverInfoare null. Other simple types has values from datatable.
What's the reason of this problem?
Thank you.
P.S. It's my first issue, don't judge too harshly.
Further technical details
EF Core version: 3.0.0-preview7.19362.6
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Database: Microsoft SQL Server 2017 Express
Operating system: Windows Server 2012 R2
IDE: Visual studio 2019 16.3.0 Preview 1.0
I'm having similar issues with owned types in preview 7, values are never retrieved from the db.
I'm not sure if this is still due to the query pipeline overhaul, one of the update threads listed that some of the owned type functionality had been implemented, but I wasn't sure whether that was in preview 7.
I've tried to chop it down to a standalone demo, shipping address always null -
```C#
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace OwnedTypesTest
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new TestContext())
{
ctx.Database.EnsureCreated();
ctx.Add(new Order { SomeString = "blah", ShippingAddress = new Address() { City = "Benalla", Street = "Cowan" } });
ctx.Add(new Order { SomeString = "another blah", ShippingAddress = new Address() { City = "Baddaginnie", Street = "Not Cowan" } });
ctx.SaveChanges();
}
using (var ctx = new TestContext())
{
var items = ctx.Set
Console.WriteLine($"Total Orders: '{items.Count}' ");
foreach (var order in items)
{
Console.WriteLine($"Info: '{order.SomeString}' shipping to: {order.ShippingAddress.City} ");
}
}
Console.ReadKey();
}
}
public class Order
{
public int Id { get; set; }
public string SomeString { get; set; }
public Address ShippingAddress { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
public class TestContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=TestDB");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Order>().OwnsOne(o => o.ShippingAddress, oa =>
{
oa.Property<string>("Street");
oa.Property<string>("City");
});
}
}
}
```
Further technical details
EF Core version: 3.0.0-preview7.19362.6
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual studio 2019
In the EF Core breaking changes said that you should use WithOwner() for owned types mapping. But I think, your code won't be worked as expected after correcting too...
Yeah I've tried many many different combinations of config, I can't find one that works. If you have
C#
modelBuilder.Entity<Order>().OwnsOne(o => o.ShippingAddress).WithOwner();
Or without the withowner etc, still nothing.
All this worked in preview 5, I never tried preview 6 because it seemed all this was broken with the query rework, but I had thought some was re implemented for preview 7
"All this worked in preview 5, I never tried preview 6" - me too. Waiting for developers' comments...
This is fixed in the currently nightly builds. Duplicate of #16775
Most helpful comment
Yeah I've tried many many different combinations of config, I can't find one that works. If you have
C# modelBuilder.Entity<Order>().OwnsOne(o => o.ShippingAddress).WithOwner();Or without the withowner etc, still nothing.
All this worked in preview 5, I never tried preview 6 because it seemed all this was broken with the query rework, but I had thought some was re implemented for preview 7