Vishal
Vishal

Reputation: 2017

Casting Errors on getting datetime value from db using Linq in MVC

Problem Statement:

I'm trying to get the datetime value from the table using some where conditions but it is giving exception as : LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.

Linq Query what i'm trying :

Datetime PDate=(from p in db.PMaster
                      where p.ID == ID
                      && p.PNumber == Num
                      select p.PDate).SingleOrDefault();

I'm trying to get Datetime column(PDate) value from the the db using linq and assigning it to variable.

What i'm doing wrong??

Upvotes: 1

Views: 102

Answers (1)

Vishal
Vishal

Reputation: 2017

Solution:

Based on @Tim.Tang comment, following code snippet solved my problem

Datetime PDate=(from p in db.PMaster.AsEnumerable()
                      where p.ID == ID
                      && p.PNumber == Num
                      select p.PDate).SingleOrDefault();

Upvotes: 2

Related Questions