我知道“连接”在客户端不支持WCF DS,这就是为什么我决定在服务器端添加一个方法来执行“连接”并返回结果作为自定义类型对象。 服务看起来是这样的:如何在WCF数据服务的服务端执行连接操作
public class CWcfDataService : DataService<CEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.RegisterKnownType(typeof(CASE_STAGE_HISTORY_EXTENDED));
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
[WebGet]
public IQueryable<CASE_STAGE_HISTORY_EXTENDED> GetCASE_STAGE_HISTORY_EXTENDEDByDocId(int docId)
{
CEntities context = new CEntities();
return (from c in context.CASE_STAGE_HISTORY
join a in context.USRs on c.CREATOR_ID equals a.USRID
select new CASE_STAGE_HISTORY_EXTENDED()
{
CASE_STAGE_ID = c.CASE_STAGE_HISTORY_ID,
CASE_STAGE_NAME = c.CASE_STAGE_NAME,
CREATE_DATE = c.CREATE_DATE,
CREATOR_ID = c.CREATOR_ID,
DOC_ID = c.DOC_ID,
LAST_VARIANT_DOCUMENT_ID = c.LAST_VARIANT_DOCUEMENT_ID,
CREATOR_FULLNAME = a.FULLNAME
});
}
}
和定制类:
[DataServiceKey("CASE_STAGE_ID")]
public class CASE_STAGE_HISTORY_EXTENDED
{
public int CASE_STAGE_ID { get; set; }
public int DOC_ID { get; set; }
public string CASE_STAGE_NAME { get; set; }
public int? LAST_VARIANT_DOCUMENT_ID { get; set; }
public DateTime? CREATE_DATE { get; set; }
public int? CREATOR_ID { get; set; }
public string CREATOR_FULLNAME { get; set; }
}
当我尝试更新Visual Studio的服务参考我不断得到错误:
如果我删除public IQueryable<CASE_STAGE_HISTORY_EXTENDED> GetCASE_STAGE_HISTORY_EXTENDEDByDocId(int docId)
部分 - 更新服务参考我得到另一个错误:
The server encountered an error processing the request. The exception message is 'Internal Server Error. The type 'CourtWcf.Code.CASE_STAGE_HISTORY_EXTENDED' is not a complex type or an entity type.'.
环境:Visual Studio 2010中,.NET 4
异常消息是'无法加载方法'System.Collections.Generic.IEnumerable'1 [CWcf.Code。')的'返回类型的元数据'System.Collections.Generic.IEnumerable'1 [CWcf.Code.CASE_STAGE_HISTORY_EXTENDED]'。 CASE_STAGE_HISTORY_EXTENDED] GetCASE_STAGE_HISTORY_EXTENDEDByDocId(Int32)'。'。 – 0x49D1 2011-02-24 10:06:43
你的类型是可串行化的吗?你测试过它是可序列化的吗? – 2011-02-24 10:16:53
@nihi_l_ist,尝试在返回之前通过调用ToList()方法将查询转换为“List”。 – 2011-02-24 10:22:55