我的 EF 模型是从我的 SQL Server 数据库生成的。然后,我针对 EF 模型为 RIAServices 生成了 DomainService。其中一个实体称为“EntryCategories”。DomainService 创建了这个方法:
public IQueryable<EntryCategories> GetEntryCategoriesSet()
{
return this.Context.EntryCategoriesSet;
}
由于我的用户界面显示模型看起来与物理模型完全不同,因此我决定为该实体和相关实体编写自己的 DomainService。是的,我知道我们打算修改生成的那个,但是里面有很多东西,我想专注于一件小事。
我从生成的 DomainService 中删除了EnableClientAccess属性,并添加了一个名为 ClientDomainService 的新类,并将生成的 DomainService 封装在其中:
[EnableClientAccess()]
public class ClientDomainService : DomainService
{
// the generated domain service encapsulated in my new one.
private DataDomainService _dcds = new DataDomainService();
// reimplement one of the DataDomainService methods
public IQueryable<EntryCategories> GetEntryCategories()
{
return (from t in _dcds.GetEntryCategoriesSet() where t.EntryCategoriesVersions.EntryCategoriesVersionId == datahead.EntryCategoriesVersions.EntryCategoriesVersionId orderby t.DisplayOrder select t);
}
}
我尝试的第一件事是重新实现 GetCateogoriesSet 方法,但基础数据基于我类中的另一个实体(未显示)过滤。但是当我构建它时,会出现一个错误:
Entity 'DataProject.Web.EntryCategories' has a property 'EntryCategoriesVersionsReference' with an unsupported type
如果我注释掉我的 CientDomainService,替换生成的 DomainService 上的EnableClientAccess属性,并将类似的 linq 过滤放在原始的 GetEntryCategoriesSet 方法中,则项目编译没有错误。
生成的 DomainService 有什么特别之处而我的新服务没有?是那个 metadata.cs 文件吗?