Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Linq: LINQ to Entities does not recognize the method System.DateTime AddDays(Double) method

06.08.2018 (👁7428)


 

Fehlermeldung:

System.NotSupportedException

  HResult=0x80131515

  Message=LINQ to Entities does not recognize the method 'System.DateTime AddDays(Double)' method, and this method cannot be translated into a store expression.

  Source=EntityFramework

EF: Datetime nicht direkt eingeben

var data = db.tbl_Scans.Where(s => s.dtListed < DateTime.Now.AddDays(-2));

Richtig, OK:

var data = db.tbl_Scans.Where(s => s.dtListed < System.Data.Entity.DbFunctions.AddDays(DateTime.Now,-2));

 

 

 

Fehlerhafter Code

var db = new dbAppData_Context();

 

var data = db.tbl_Scans.Where(s => s.dtListed < DateTime.Now.AddDays(-2));

foreach (tbl_Scans rec in data)

{

    rec.dtDeleted = DateTime.Now;

}

db.SaveChanges();

 

 

Korrigierter Code

var db = new dbAppData_Context();

 

var data = db.tbl_Scans.Where(s => s.dtListed < System.Data.Entity.DbFunctions.AddDays(DateTime.Now,-2));

foreach (tbl_Scans rec in data)

{

    rec.dtDeleted = DateTime.Now;

}

db.SaveChanges();