#

 

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();

 

 

Mobile

.