Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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,我想更新通过LINQ获取的行的列,要更新的属性存储在字符串中。如何通过检查该属性是否等于该字符串来具体更新该值,然后更改属性值并保存更改 例如: string prop_name= "Gate3"; IList<Model_name> DataList = (from q in DB.Table Select q ).toList(); if(DataList.Count <> 0) { //do foreach loop and update the colu

我想更新通过LINQ获取的行的列,要更新的属性存储在字符串中。如何通过检查该属性是否等于该字符串来具体更新该值,然后更改属性值并保存更改

例如:

string prop_name= "Gate3";
IList<Model_name> DataList = (from q in DB.Table Select q ).toList();

if(DataList.Count <> 0)
{
    //do foreach loop and update the column name Gate3 
    // which is the property in the model .  
}
string prop_name=“Gate3”;
IList DataList=(从DB.Table中的q选择q.toList();
如果(DataList.Count 0)
{
//执行foreach循环并更新列名Gate3
//这是模型中的属性。
}

假设DB对象是DataContext对象,它正在跟踪其实体中的更改。在修改其中一些内容后,只需调用DB.SaveChanges(),它将提交您的更新。

LINQ用于查询数据,它不会操作原始集合。您可以展示您迄今为止尝试的内容吗?您的表应该规范化,以不使用编号为
Gate1
Gate2
Gate3
等的列。您的应用程序应该是可配置的,以便如果安装在“gate”3您可以编辑一个设置,以便应用程序知道它使用的是哪个门。这不是我的应用程序,它是在我加入该公司之前构建的。。嗯,有时候我不得不坚持使用这个数据库,直到我换了工作:D