【发布时间】:2011-07-15 22:42:59
【问题描述】:
我有一个简单的 DTO,我试图通过 RIAServices 返回,但我不断收到此错误: “查询的加载操作失败。无法创建“System.Object”类型的常量值。此上下文仅支持原始类型。
查询方法如下:
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();
}
我通过使用 == 而不是 Equals 来实现它。这是有问题的:
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);
【问题讨论】:
标签: c# linq-to-sql