我已经安装了最新版本的 Breeze 1.3.2 以支持继承。我有一个具有双向关联的分层类:
public abstract class HClass
{
public HClass()
{
Children = new List<HClass>();
}
[Key]
public int Id { get; set; }
public Nullable<int> ParentId { get; set; }
public string Name { get; set; }
public virtual ICollection<HClass> Children { get; set; }
public virtual HClass Parent { get; set; }
}
我有其他继承类:
public class AClass : HClass
{
public string Observation { get; set; }
}
public class BClass : HClass
{
public int Number { get; set; }
}
服务器中的 DbContext:
public DbSet<AClass> Projects { get; set; }
public DbSet<BClass> OtherProjects { get; set; }
服务器端控制器方法:
[HttpGet]
public ICollection<AClass> Projects()
{
ICollection<AClass> projects = new List<AClass>();
AClass pro1 = new AClass(); AClass pro2 = new AClass(); AClass pro3 = new AClass(); AClass pro4 = new AClass();
pro1.Id = 1;
pro1.Name = "Project 1";
pro1.Observation = "Main";
pro2.Id = 2;
pro2.Name = "Project 2";
pro2.Observation = "Main";
pro3.Id = 3;
pro3.Name = "Sub Project 3";
pro3.ParentId = 1;
pro3.Parent = pro1;
pro4.Id = 4;
pro4.Name = "Sub Project 4";
pro4.ParentId = 1;
pro4.Parent = pro1;
pro1.Children.Add(pro3);
pro1.Children.Add(pro4);
projects.Add(pro1);
projects.Add(pro2);
return projects;
}
“projects”中的每个item都设置了“Parent”和“Children”item,方法Projects返回层次结构。
但我有下一个错误Collection navigation properties may NOT be set.
。当我查询时:
return entityQuery.from('Projects')
.using(manager).execute()
.then(success)
.fail(queryFailed);
错误在breeze.debug.js
:
function updateRelatedEntity(relatedEntity, targetEntity, navigationProperty) {
if (!relatedEntity) return;
var propName = navigationProperty.name;
var currentRelatedEntity = targetEntity.getProperty(propName);
// check if the related entity is already hooked up
if (currentRelatedEntity !== relatedEntity) {
// if not hook up both directions.
targetEntity.setProperty(propName, relatedEntity); //Error here
var inverseProperty = navigationProperty.inverse;
if (!inverseProperty) return;
if (inverseProperty.isScalar) {
relatedEntity.setProperty(inverseProperty.name, targetEntity);
} else {
var collection = relatedEntity.getProperty(inverseProperty.name);
collection.push(targetEntity);
}
}
}
当我使用HClass
时,微风可以完美地工作,但是当我使用AClass
或BClass
使用继承时会出现错误。
我已更新到 Breeze 1.3.3 但错误仍然存在
请帮我解决这个错误,欢迎提出任何建议。