I have a simple DTO that I'm trying to return via RIAServices and I keep getting this error: "Load operation failed for query. Unable to create constant value of type 'System.Object'. Only primitive types are supported in this context.
Here's the query method:
public IQueryable<SupportDbDTO> GetDbsRelatedToModel(string modelDtoId)
{
IQueryable<SupportDb> query;
var key = new Guid(modelDtoId);
var siteId = _context.SupportDbs.Single(db => db.Id.Equals(key)).SiteDbId ?? Guid.Empty;
query = _context.SupportDbs
.Where(db => !db.Id.Equals(key))
.Where(db => db.DBType == DB.CATALOG_DB || db.DBType == DB.CATALOG_SCHEMA_DB || db.DBType == DB.MODEL_DB)
.Where(db => db.SiteDbId.Equals(siteId))
.OrderBy(db => db.DBName);
return query.AsEnumerable()
.Select(db => new SupportDbDTO
{
Id = db.Id.ToString(),
DBName = db.DBName,
DBType = db.DBType,
PlantRoot = db.PlantRoot,
DBSize = db.DBSize ?? 0,
ModifiedDate = db.ModifiedDate ?? DateTime.Now
}).AsQueryable();
}
I got it to work by using == instead of Equals. This was the offending one:
query = _context.SupportDbs
.Where(db => db.Id != key)
.Where(db => db.DBType == DB.CATALOG_DB || db.DBType == DB.CATALOG_SCHEMA_DB || db.DBType == DB.MODEL_DB)
.Where(db => db.SiteDbId == siteId)
.OrderBy(db => db.DBName);
thanks Sunit