如何处理没有其他关系的实体中的嵌套对象

How to handle nested object in Entities that have no other relation

考虑以下 class:

public class Country{
   public string Name {get;set;}
   public Coordinate Coordinate {get;set;}
}
public class Coordinate{
   public Latitude {get;set;}
   public Longitude {get;set;}
}

现在,当我创建一个迁移时,它会创建两个 tables:CountryCoordinate 以及两个 tables 之间的映射。

Table: Country
[id, name, coordinateId]

Table: Coordinate
[id, latitude, longitude]

这感觉很可疑,因为坐标与其他任何东西都没有关系。它也可以存储在相同的 table.

我觉得更好的方法是让 1 table [Country] 包含所有字段:

Table: Country
[id, name, coordinate_latitude, coordinate_longitude]

是不是acceptable在EF中有很多嵌套对象的tables,这些嵌套对象填充的数据仅供其主要父级使用?或者有没有办法 'flatten' 更有效的对象?

https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/implement-value-objects

有一个示例如何将值对象设置为主 table 中的列:

orderConfiguration.OwnsOne(p => p.Address) .属性(p=>p.Street).HasColumnName("ShippingStreet");

orderConfiguration.OwnsOne(p => p.Address) .属性(p=>p.City).HasColumnName("ShippingCity");

为什么不使用 SqlGeography

public class Country{
   public string Name {get;set;}
   public SqlGeography Coords {get;set;}
}

否则你可以把 class 弄平。

public class Country{
   public string Name {get;set;}
   public double Latitude {get;set;}
   public double Longitude {get;set;}
}