2012-02-17 54 views
0

我有以下實體框架的實體:微軟莫爾斯:循環引用錯誤?

public class Country 
{ 
    public long Id { get; set; } 
    public string Code { get; set; } 
    public virtual ICollection<Person> Persons { get; set; } 
} 

public class Person 
{ 
    public long Id { get; set; } 
    public long? Country_Id { get; set; } 
    public Country HomeCountry { get; set; } 
} 

痣產生了MPersonMCountry存根類。

現在我想存根集COUNTRY_ID的:

MPerson.AllInstances.Country_IdSetNullableOfInt64 = (Person instance, long? id) => 
{ 
    // Do something 

    // Set the Country_Id to the provided id 
    // This will trigger this same method again and again. How to avoid this ? 
    instance.Country_Id = id; 
}; 

回答

0

This post給出了答案:

MolesContext.ExecuteWithoutMoles(() => instance.Country_Id = id);