LINQ to Entities does not recognize the method 'System.String get_Item (System.String)',

后端 未结 3 656
滥情空心
滥情空心 2021-01-17 13:31

How can I solve this problem?

Here is my code:

    DateTime dtInicio = new DateTime();
    DateTime dtFim = new DateTime();
    Int32 codStatus = 0;
         


        
3条回答
  •  既然无缘
    2021-01-17 13:38

    In one line...

    DO NOT USE STRING CONVERSION FUNCTIONS in Linq(Entity) Query!

    Wrong:

    user = db.Users.Where(u => u.Name == dt.Rows[i]["Name"].ToString()).FirstOrDefault();
    

    Correct:

    string Name = dt.Rows[i]["Name"].ToString();
    user = db.Users.Where(u => u.Name == Name).FirstOrDefault();
    

提交回复
热议问题