Я получаю сообщение об ошибке, когда пытаюсь использовать собственный тип в нескольких объектах. Я думаю, что получил ошибку, потому что User
использовал тот же тип. Использование одного и того же типа в нескольких сущностях не поддерживается ядром EF?
System.InvalidOperationException: Тип сущности 'Hitasp.Tradegram.Types.Location' нельзя добавить в модель, поскольку слабый тип сущностис таким именем уже существует.
public class User : IEntity<Guid>
{
public Guid Id { get; set; }
public ContactInfo UserContactInfo { get; set; }
}
public class Listing : IEntity<Guid>
{
public Guid Id { get; set; }
public ContactInfo ListingContactInfo { get; set; }
}
public class ContactInfo : IOwnedType
{
public string WebsiteUrl { get; set; }
public Location GeoLocation { get; set; }
}
public class Location : IOwnedType
{
public NetTopologySuite.Geometries.Point Coords { get; set; }
public Address PhysicalAddress { get; set; }
}
public class Address : IOwnedType
{
public string AddressLine1 { get; set; }
public string ZipPostalCode { get; set; }
}
//User modelBuilder
userBuilder.OwnsOne(c => c.UserContactInfo, conInfo =>
{
conInfo.ToTable("UsersContactInfo");
conInfo.OwnsOne(ci => ci.GeoLocation, location =>
{
location.OwnsOne(x => x.PhysicalAddress, address =>
{
address.ToTable("UsersPhysicalAddresses");
});
location.Property(x => x.Coords).HasColumnType("geography");
location.ToTable("UsersLocations");
});
});
//Listing modelBuilder
listingBuilder.OwnsOne(c => c.ListingContactInfo, conInfo =>
{
conInfo.ToTable("ListingsContactInfo");
conInfo.OwnsOne(ci => ci.GeoLocation, location =>
{
location.OwnsOne(x => x.PhysicalAddress, address =>
{
address.ToTable("ListingsPhysicalAddresses");
});
location.Property(x => x.Coords).HasColumnType("geography");
location.ToTable("ListingsLocations");
});
});
файл: 13980720151831_Initial_I.Designer.cs # line2808
modelBuilder.Entity("Hitasp.Tradegram.Authorization.Users.User", b =>
{
b.OwnsOne("Hitasp.Tradegram.Types.ContactInfo", "UserContactInfo", b1 =>
{
b1.Property<Guid>("UserId");
b1.Property<string>("WebsiteUrl");
b1.HasKey("UserId");
b1.ToTable("UserContactInfo");
b1.HasOne("Hitasp.Tradegram.Authorization.Users.User")
.WithOne("UserContactInfo")
.HasForeignKey("Hitasp.Tradegram.Types.ContactInfo", "UserId")
.OnDelete(DeleteBehavior.Cascade);
b1.OwnsOne("Hitasp.Tradegram.Types.Location", "GeoLocation", b2 =>
{
b2.Property<Guid>("ContactInfoUserId");
b2.Property<Point>("Coords")
.HasColumnType("geography");
b2.HasKey("ContactInfoUserId");
b2.ToTable("UserLocations");
b2.HasOne("Hitasp.Tradegram.Types.ContactInfo")
.WithOne("GeoLocation")
.HasForeignKey("Hitasp.Tradegram.Types.Location", "ContactInfoUserId")
.OnDelete(DeleteBehavior.Cascade);
b2.OwnsOne("Hitasp.Tradegram.Types.Address", "PhysicalAddress", b3 =>
{
b3.Property<Guid>("LocationContactInfoUserId");
b3.Property<string>("AddressLine1");
b3.Property<string>("ZipPostalCode");
b3.HasKey("LocationContactInfoUserId");
b3.ToTable("UserPhysicalAddresses");
b3.HasOne("Hitasp.Tradegram.Types.Location")
.WithOne("PhysicalAddress")
.HasForeignKey("Hitasp.Tradegram.Types.Address", "LocationContactInfoUserId")
.OnDelete(DeleteBehavior.Cascade);
});
});
});
});
файл: 13980720151831_Initial_I.Designer.cs # line3019
modelBuilder.Entity("Hitasp.Tradegram.Listings.Listing", b =>
{
b.OwnsOne("Hitasp.Tradegram.Types.ContactInfo", "ListingContactInfo", b1 =>
{
b1.Property<Guid>("ListingId");
b1.Property<string>("WebsiteUrl");
b1.HasKey("ListingId");
b1.ToTable("ListingContactInfo");
b1.HasOne("Hitasp.Tradegram.Listings.Listing")
.WithOne("ListingContactInfo")
.HasForeignKey("Hitasp.Tradegram.Types.ContactInfo", "ListingId")
.OnDelete(DeleteBehavior.Cascade);
b1.OwnsOne("Hitasp.Tradegram.Types.Location", "GeoLocation", b2 =>
{
b2.Property<Guid>("ContactInfoListingId");
b2.Property<Point>("Coords")
.HasColumnType("geography");
b2.HasKey("ContactInfoListingId");
b2.ToTable("ListingLocations");
b2.HasOne("Hitasp.Tradegram.Types.ContactInfo")
.WithOne("GeoLocation")
.HasForeignKey("Hitasp.Tradegram.Types.Location", "ContactInfoListingId")
.OnDelete(DeleteBehavior.Cascade);
b2.OwnsOne("Hitasp.Tradegram.Types.Address", "PhysicalAddress", b3 =>
{
b3.Property<Guid>("LocationContactInfoListingId");
b3.Property<string>("AddressLine1");
b3.Property<string>("ZipPostalCode");
b3.HasKey("LocationContactInfoListingId");
b3.ToTable("ListingPhysicalAddresses");
b3.HasOne("Hitasp.Tradegram.Types.Location")
.WithOne("PhysicalAddress")
.HasForeignKey("Hitasp.Tradegram.Types.Address", "LocationContactInfoListingId")
.OnDelete(DeleteBehavior.Cascade);
});
});
});
});
Дополнительные технические данные
Версия EF Core: 2.2.6 Поставщик базы данных: Microsoft.EntityFrameworkCore.SqlServer Целевая структура: .NET Core 2.2 Операционная система: Windows 10 IDE: Rider 2019.2.2