[英]Pass table name to dbContext and get values from table in Entity Framework
[英]How to get values from a table in entity framework?
在InsertData类中,我想从Combobox cbxCategory
获取值,但由于dshang.tblCategory
是一个表而无法获取。
错误如:
无法将类型'string'隐式转换为'EntityObject.tblCategory'(这是一个表)
Category dshang = new Category();
string category = cbxCategory.SelectedValue.ToString();
dshang.tblCategory = category;
在实体数据模型中,我定义它是一个表。 因此,我无法从中获得此值。
public partial class ListProduct
{
public virtual tblCategory tblCategory { get; set; }
}
这里包含类定义表tblPhanLoai
:
public partial class tblCategory
{
public tblCategory()
{
this.ListProducts = new HashSet<ListProduct>();
}
public string ID { get; set; }
public string Description { get; set; }
public string DonViTinh { get; set; }
public virtual ICollection<ListProduct> ListProducts { get; set; }
}
您正在为对象分配一个简单的字符串...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.