我有以下课程:
public abstract class Contact
{
public int Id { get; set; }
public ICollection<Address> Addresses { get; set; }
public ICollection<ContactProfile> Profiles { get; set; }
public ICollection<ContactProfile> ContactProfiles { get; set; }
}
[Table("Persons")]
public class Person : Contact
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Organization Employer { get; set; }
}
[Table("Organizations")]
public class Organization : Contact
{
public string Name { get; set; }
}
public class ContactProfile
{
public int Id { get; set; }
public int ContactId { get; set; }
public int ProfileId { get; set; }
public virtual Contact Contact { get; set; }
public virtual Contact Profile { get; set; }
}
使用以下流畅的 API 映射:
modelBuilder.Entity<Contact>()
.HasMany(c => c.Profiles)
.WithRequired(c => c.Contact)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Contact>()
.HasMany(c => c.ContactProfiles)
.WithRequired(c => c.Profile)
.WillCascadeOnDelete(false);
我的 BreezeApi 方法:
public IQueryable<Contact> Contacts()
{
var contacts = _contextProvider.Context.Contacts
.Include("Profiles")
//.Include("Profiles.Contact") // Object expected on client side
.Include("Addresses")
return contacts;
}
当我想用微风查询检索数据时:
var query = entityQuery.from("Contacts");
BreezeJS 将引发对象预期异常:
TypeError: Object expected
at Anonymous function (../breeze.debug.js:13283:36)
但仅当我想从联结表(ContactProfile)加载导航属性时,包括“Profiles.Contact”等。
服务器端一切正常,数据库也生成成功。
我错过了什么?
编辑:
我已经更新了我的数据模型。仅当设置了雇主和 ContactProfile 关系时,才会出现异常:
var people = new List<Person>
{
new Person
{
FirstName = "Jan Dae",
LastName="Dae",
Addresses = new List<Address>{addresses[0]},
Employer = organizations[0] // Exception when both are set
}
};
people.ForEach(p => context.Contacts.Add(p));
var references = new List<ContactProfile>
{
new ContactProfile
{
Contact = people[0],
Profile = organizations[0] //Exception when both are set
}
};
references.ForEach(r => context.ContactProfiles.Add(r));