简体   繁体   English

在WCF服务中公开为对象的数据库实体

[英]Database entity exposed as object in WCF service

I have a WCF service in which I have a method which returns an IQueryable of an object representing a database table (Accommodation) using Entity Framework. 我有一个WCF服务,其中有一个方法,该方法使用Entity Framework返回表示数据库表(住宿)的对象的IQueryable。 When I try and use that method on the client side the method does not return IQueryable but object. 当我尝试在客户端使用该方法时,该方法不会返回IQueryable而是对象。 I looked at the code for the service and the Accommodation class that Entity Framework generates has this attribute 我查看了服务的代码,实体框架生成的Accommodation类具有此属性

[DataContractAttribute(IsReference=true)]

So, AFAIK the client should be able to see that class. 因此,AFAIK客户端应该能够看到该类。 What is going wrong here? 这是怎么了?

Thanks, 谢谢,

Sachin 萨钦

The type will only appear in the metadata if it is used on the contract. 该类型仅在合同中使用时才会显示在元数据中。 The metadata has no idea what IQueryable is - its a definition of behavior whereas the contract only defines state so the generated code will use somethingit does understand in this situation - ie object 元数据不知道IQueryable是什么-它是行为的定义,而合同仅定义状态,因此生成的代码将使用在这种情况下可以理解的东西-即对象

It is really not a good idea to use the EF generated types on your service contract - you, in effect, tightly couple your service consumers to your data access layer. 在服务合同中使用EF生成的类型确实不是一个好主意-实际上,您将服务使用者与数据访问层紧密耦合。 Use EF internally in the service and use types which define the data you want to pass around on the service boundary 在服务内部使用EF并使用定义您要在服务边界传递的数据的类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM