LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression

前端 未结 3 2002
不思量自难忘°
不思量自难忘° 2020-11-27 23:47

I am using Entity Framework, and I have a line of code that is taking a var and translating it back to an iint for the database.

var record = context.enrollm         


        
3条回答
  •  青春惊慌失措
    2020-11-28 00:16

    This works for me:

      var iId = int.Parse(TextBox1.Text);
     var item = db.Items.Where(p => p.ItemID == iId ).FirstOrDefault();
    

    To make that work you should convert your textbox value outside of the lambda expression.

提交回复
热议问题