2012-02-17 31 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);