【问题标题】:How to select a column name using Linq [duplicate]如何使用 Linq 选择列名 [重复]
【发布时间】:2019-02-12 13:21:52
【问题描述】:

我陷入了我的逻辑需要一些改进的情况,我正在努力做到这一点。 情况是我们都知道如何像这样更新列的具体细节。

Person result = (from p in Context.Persons
          where p.person_id == 5
          select p).SingleOrDefault();

result.is_default = false;

Context.SaveChanges();

好的,一切顺利!

现在假设我在会话 is_default 中有一个值,即表的列名。

如何使用该值更新列,如下所示:

update table name set "Session value" = true 

这里的会话值是is_default,它是表的列名。这可能使用 EF , LINQ 吗?

【问题讨论】:

    标签: c# entity-framework linq


    【解决方案1】:

    您可以使用下面给出的反射概念

    Person result = (from p in Context.Persons
              where p.person_id == 5
              select p).SingleOrDefault();
    
    PropertyInfo propertyInfo = result.GetType().GetProperty("Session value");
    propertyInfo.SetValue(result , true, null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2021-09-17
      相关资源
      最近更新 更多