编程语言
首页 > 编程语言> > c# – 异常消息是On数据上下文类型,有一个顶级的IQueryable属性,其元素类型不是实体类型

c# – 异常消息是On数据上下文类型,有一个顶级的IQueryable属性,其元素类型不是实体类型

作者:互联网

我建立了我在IIS 7中托管的WCFDataService,我将使用Reflection Provider作为数据源提供者.
如果我将实体类型定义保存在我定义服务的同一个程序集中,我的示例工作,但如果我将实体类型移动到另一个引用的程序集,则不起作用
有以下错误

“server encountered an error processing the request. The exception message is ‘On data context type ‘EntityContainer’, there is a top IQueryable property ‘Cats’ whose element type is not an entity type”

服务

public class WcfDataService1 : DataService<EntityContainer>
    {

        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("Cats", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

        }
    }

实体容器

public class EntityContainer
    {
        public IQueryable<Cat> Cats
        {
            get
            {
                var s = new List<Cat>();
                var c1 = new Cat {Id = 1, Name = "Fufi"};
                var c2 = new Cat {Id = 1, Name = "Felix"};
                s.Add(c1);
                s.Add(c2);
                return s.AsQueryable();
            }
        }

    }

实体类型

[DataServiceKey("Id")]
public  class Cat 
{
     public int Id { get; set; }

     public string Name { get; set; }
}

现在,正如我上面说的那样,如果我将类Cat与其他代码保持在一起,那么我会发现错误,但如果我将Cat移动到引用的程序集中,我会收到错误

什么我失踪了?

解决方法:

经过2个小时和强烈的头疼我自己发现了问题,我在我的服务中引用了Microsoft.Data.Services.Client,在引用的项目库中引用了System.Data.Services.Client,我将移动实体类型.希望我的帖子可以帮助别人.谢谢

标签:c,net,wcf,odata,wcf-data-services
来源: https://codeday.me/bug/20190528/1172304.html