Entity framework 实体框架关系
我正在尝试制作一个应用程序,但遇到了一个小问题。我的结构如下所示:Entity framework 实体框架关系,entity-framework,entity-framework-core,Entity Framework,Entity Framework Core,我正在尝试制作一个应用程序,但遇到了一个小问题。我的结构如下所示: public class BaseModel { [Key] private int _Id; public int Id { get { return _Id; } set { _Id = value; } } } public class SupplierModel : Base
public class BaseModel
{
[Key]
private int _Id;
public int Id {
get { return _Id; }
set { _Id = value; }
}
}
public class SupplierModel : BaseModel
{
[ForeginKey("CountryCode")] // This should map to say "se" or "no" or whatever in the CountryModel table
public virtual CountryModel Country;
}
public class CountryModel : BaseModel
{
private string _CountryCode;
[Key] // This should be another key in the table to get the actual country.
public string CountryCode {
get { return _CountryCode; }
set { _CountryCode = value; }
}
private string _CountryName;
public string CountryName {
get { return _CountryName; }
set { _CountryName = value; }
}
}
现在我希望SupplierModel链接到CountryModel(根据Id可以正常工作),但我希望它是国家代码,而不是实体之间的Id
所以访问CountryModel.Country应该映射到CountryModel表,并拉出与CountryModel匹配的表
希望我没有为你们把事情搞得一团糟,当我不完全理解实体框架和数据库关系时,很难解释。。尝试学习=)这能回答你的问题吗?问题是什么?