我使用实体框架一对一的关系在WCF服务器端,主要代码:为什么Entity Framework WCF客户端中的一对一关系为空?
[DataContract]
public class AppType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DataMember]
public int TypeID { get; set; }
[DataMember]
public string TypeName { get; set; }
}
[DataContract]
public class App
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DataMember]
public long AID { get; set; }
[DataMember]
[ForeignKey("AppType")]
public int TypeID { get; set; }
[DataMember]
public DateTime DateAdded { get; set; }
[DataMember]
public virtual AppType AppType { get; set; }
//...
}
因为序列化的问题,我必须关闭惰性加载和proxyclass在EF:
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
现在, WCF的客户端可以工作,但我不能用“应用”获得“的AppType”:
的GetAppByTypeidContentid方法是:
public App GetAppByTypeidContentid(string contentid, int typeid)
{
using (var db = new TagDbContext())
{
try
{
var app = db.Apps.SingleOrDefault(a => a.ContentID.Trim() == contentid.Trim() && a.TypeID == typeid);
if (app != null)
{
return app;
}
else
{
throw new Exception("App not exist!");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
是否必须使用DTO?谁可以帮我感谢
显示你'GetAppByTypeidContentid'实现 - 尤其是部分查询EF? –
我提供的GetAppByTypeidContentid代码高于 – artwl