我已经安装了最新版本的Breeze 1.3.2 for Inheritance support。 我有一个带有双向关联的分层类:
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;
}
“项目”中的每个项目都设置了“父项”和“子项”项目,方法项目返回了层次结构。
但我有下一个错误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
时,breeze工作正常,但当我使用AClass
或BClass
继承时会出现错误。
我已更新到Breeze 1.3.3但错误仍然存在
请帮助我解决此错误,欢迎任何建议。
答案 0 :(得分:1)
我们无法重现您的错误,所以您可以通过电子邮件将显示错误的“小”测试用例通过电子邮件发送到breeze.ideablade.com(在电子邮件中的某处有Attn:Jay Traband)。 Breeze zips中最新的DocCode示例有一个“Inheritance.sdf”数据库和一个与你的非常相似的InheritanceController类,如果你需要一个地方可以启动的话。