我有基于nHibernate数据访问的OData WCF服务。一切正常,但我想使用" Expand"加载相关数据。 这是我的代码:
[DataServiceKey("Id")]
public class Product : BaseEntity
{
public Product()
{
CreatedDate = DateTime.UtcNow;
}
public virtual long Id { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual User CreatedBy { get; set; }
public virtual string Name { get; set; }
public virtual string Symbol { get; set; }
public virtual decimal Weight { get; set; }
public virtual Tax Tax { get; set; }
[EntityCustomAttribute(UseOnFK = true)]
public virtual ProductAttributeGroup AttributeGroup { get; set; }
}
[DataServiceKey("Id")]
public class ProductAttributeGroup : BaseEntity
{
public ProductAttributeGroup()
{
Products = new List<Product>();
}
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int OrderBy { get; set; }
public virtual IList<Product> Products { get; set; }
}
//this is odata service client code:
var dbResults = DataServiceBus.ExecuteService(s => s.Products.Expand("AttributeGroup").Where(GetQuery(query))).OrderBy(GetOrderBy(query))
.Skip(query.Skip).Take(query.Take).Select(x => new ProductListItemViewModel()
{
Id = x.Id,
Name = x.Name,
GroupName = x.AttributeGroup.Name,
Symbol = x.Symbol,
Weight = x.Weight
}).ToList();
当我尝试执行我的客户端代码时,我总是发现错误: 处理响应流时出错。服务器失败并显示以下消 内部服务器错误。类型&#39; ProductAttributeGroupProxy&#39;不是复杂类型或实体类型。
看起来OData客户端无法将代理识别为有效的实体类型。有没有办法解决这个问题?