Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在实体框架中从表中获取值?_C#_Entity Framework - Fatal编程技术网

C# 如何在实体框架中从表中获取值?

C# 如何在实体框架中从表中获取值?,c#,entity-framework,C#,Entity Framework,在InsertData类中,我想从ComboboxcbxCategory中获取值,但我无法获取,因为dshang.tblCategory是一个表 错误如下: 无法将类型“string”隐式转换为“EntityObject.tblCategory”(这是一个表) 在实体数据模型中,我将其定义为一个表。所以,我不能从中得到这个值 public partial class ListProduct { public virtual tblCategory tblCategory { get;

在InsertData类中,我想从Combobox
cbxCategory
中获取值,但我无法获取,因为
dshang.tblCategory
是一个表

错误如下:

无法将类型“string”隐式转换为“EntityObject.tblCategory”(这是一个表)

在实体数据模型中,我将其定义为一个表。所以,我不能从中得到这个值

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; }
}
公共部分类TBL类别
{
公共TBL类别()
{
this.ListProducts=new HashSet();
}
公共字符串ID{get;set;}
公共字符串说明{get;set;}
公共字符串DonViTinh{get;set;}
公共虚拟ICollection列表产品{get;set;}
}

您正在为一个对象分配一个简单字符串…

您正在为一个对象分配一个简单字符串…

是的,这是实体框架中的一个对象。我不知道如何从对象中获取值使类型为StringCategory类的tblCategory属性如果combobox选择的值是来自tblCategory的描述,则可以分配
string Category=cbxCategory.SelectedValue.ToString();dshang.tblCategory.Description=类别是的,这是实体框架中的一个对象。我不知道如何从对象中获取值使类型为StringCategory类的tblCategory属性如果combobox选择的值是来自tblCategory的描述,则可以分配
string Category=cbxCategory.SelectedValue.ToString();dshang.tblCategory.Description=类别
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; }
}