1
我有有类别1和类别2字段指示类别表ID(FK)产品表格中,实体框架,变换实体
和每个字段包含一个数字(ID)。
我想为设置的类别名称添加实体时,我检索数据,但我不知道如何使category1_name和category2_name可以有类别名称。 (很难解释= 3)
EX)
public class Product
{
[Key]
public int no {get; set;}
public int category1 {get; set;} // category table ID number
public int category2 { get; set;} // category table ID number
public virtual Category category1_name {get; set;}
public virtual Category category2_name {get; set;}
}
public class Category
{
[Key]
public int no {get; set;}
public string category {get; set;}
}
但是,当我尝试检索数据,我得到了一个错误,
未知列 'Extent1.category1_name_no' 在“on子句'
如何将category1_name映射到类别表ID?
你可能想看看ForeignKeyAttribute。 – Pawel