我有WCF
服務,包含.edmx
文件,從現有數據庫中生成。在乞討有問題,在WCF
級別的數據已成功獲取併發送,但在MVC Controller
出現錯誤,該連接已關閉,因爲我的理解是因爲Configuration.ProxyCreationEnabled = true;
,當我將其更改爲false,一切似乎工作正常,直到我試圖從多個鏈接的表中獲取數據。如果通過導航屬性獲取的實體框架數據不是空的,它會導致錯誤
所以,.edmx
文件,有自動生成的類UserProfile
和Roles
public partial class UserProfile
{
public UserProfile()
{
this.webpages_Roles = new HashSet<webpages_Roles>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public virtual ICollection<webpages_Roles> webpages_Roles { get; set; }
}
而且
public partial class webpages_Roles
{
public webpages_Roles()
{
this.UserProfiles = new HashSet<UserProfile>();
}
public int RoleId { get; set; }
public string RoleName { get; set; }
public virtual ICollection<UserProfile> UserProfiles { get; set; }
}
此外,數據庫有表,包括
UserId
RoleId
由於我明白了,這叫做Navigation Property
。我的問題是 - 當我試圖發送收集到的數據一樣:
List<UserProfile> result = Context.UserProfiles
.Include(s => s.webpages_Roles)
.Where(z => z.UserId == id)
.ToList();
我收到同樣的錯誤比Configuration.ProxyCreationEnabled
是真實的。另外我注意到,在webpages_Roles Collection
爲空的情況下,一切正常,但如果至少有一條記錄 - 我收到錯誤消息。請幫助我,解決它。
另外,我配置的服務寫異常,並且該消息是
webpages_Roles'包含週期,並且如果參考跟蹤被禁止不能被序列化。'。