我使用角度为前端微风连接到EF模型。我有一个父实体(ProjectTeam),它包含一个属性,它是一个子元素数组(ProjectTeamAssociates)。我还使用可编辑的网格来编辑两个数组。
如果我添加新团队并保存,则breeze会将其正确保存到数据库。
// add teamuser
function addTeam() {
vm.inserted = datacontext.createEntity("ProjectTeam"); //create new entity
vm.inserted.ProjectID = currentID.id; //set current project id
vm.contributingTeams.push(vm.inserted); //add the new team to all teams
};
如果我向现有团队添加新员工并保存它也会有效。
// add associate
function addAssociate() {
vm.assocInserted = datacontext.createEntity("ProjectTeamAssociate");
vm.assocInserted.ProjectID = currentID.id;
vm.assocInserted.ProjectTeamID = vm.selectedTeam.ProjectTeamID;
vm.selectedTeam.ProjectTeamAssociates.push(vm.assocInserted);
//vm.contributingAssociates.push(vm.assocInserted);
};
其他重要代码:
function setAssociates(team) {
//when i select a team; team is from an ng-repeat on vm.contributingTeams
vm.selectedTeam = team;
vm.contributingAssociates = team.ProjectTeamAssociates;
}
当我尝试添加新团队然后向团队添加新的关联时,我将收到错误:“Breeze.ContextProvider.dll中发生了'System.Exception'类型的异常,但未在用户代码中处理
附加信息:INSERT语句与FOREIGN KEY约束“FK_ContributingTeamAssociate_ContributingTeam”冲突。冲突发生在数据库“Optimus”,表“dbo.ContributingTeam”,列'ContributingTeamID'。
声明已经终止。“
我一直在寻找微风文档,SO,任何随机网站的建议,我似乎无法弄清楚为什么微风不会同时添加两者。我的数据是:
entities [Object { ProjectTeamAssociateID=-2, ProjectTeamID=-1, AssociateID="00012333", more...}, Object { ProjectTeamID=-1, ProjectID=55555, TeamID=77, more...}] [0] Object { ProjectTeamAssociateID=-2, ProjectTeamID=-1, AssociateID="00012333", more...} AssociateID "00012333" Note "" ProjectTeamAssociateID -2 ProjectTeamID -1 StatusID 10 TeamRoleID 2 entityAspect Object { entityTypeName="ProjectTeamAssociate:#OptimusOnlineDataAccess", defaultResourceName="ProjectTeamAssociates", entityState="Added", more...} [1] Object { ProjectTeamID=-1, ProjectID=55555, TeamID=77, more...} Priority 0 ProjectID 55555 ProjectTeamID -1 StatusID 6 TeamID 77 entityAspect Object { entityTypeName="ProjectTeam:#OptimusOnlineDataAccess", defaultResourceName="ProjectTeams", entityState="Added", more...} saveOptions Object {}
另一个注意事项:在实体框架工作中,我们重命名为Contributing to Project。
任何想法或指示都将不胜感激。