9
I am extremely new to linq and entity framework. I am trying to resolve a problem as to why the below isn't working. The error produced is "Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context."
I've tried this so many different ways yet still get an error relating to primitive types. I would greatly appreciate it if someone could take a look at the below code and hopefully point out where it's going wrong.
public Entities.BikeData[] GetBikesWithExpiredSyncDeadline(int noOfDays) {
using (OfficeEntities cxt = GetContext())
using (ReportingEntities RepCxt = GetReportingContext()) {
Data.Repository.Abstract.IBikeRepository BikeRepos = new Data.Repository.Concrete.BikeRepository();
var details = (from sd in cxt.BikeDetails
where sd.autoreminder == true
&& (sd.lastremindersent == null || sd.lastremindersent < EntityFunctions.AddDays(DateTime.UtcNow, noOfDays * -1))
&& (sd.emailaddress != null && sd.emailaddress.Trim() != "")
select new {
Serial = sd.Serial,
EmailAddress = sd.emailaddress
}).ToList();
var resLst = (from r in RepCxt.RegisteredBikes
join d in details on r.Serial equals d.Serial
join cs in cxt.CompanySettings.ToList() on r.CompanyID equals cs.CompanyID
where (!r.lastupdate.HasValue || r.lastupdate < EntityFunctions.AddDays(DateTime.UtcNow, cs.AutoNotificationFrequency * -1))
select new Entities.BikeData {
ID =