我有两个相关的实体(我添加了所有可能的数据注释,但是ODataconVentionModelBuilder似乎忽略了它们):
public class Examination
{
[InverseProperty("Examination")]
public virtual ICollection<Variable> Variables { get; set; }
}
public abstract class Variable
{
[Required]
public int? ExaminationId { get; set; }
[Required]
[ForeignKey("ExaminationId")]
[InverseProperty("Variables")]
public virtual Examination Examination { get; set; }
}
这是ODATA模型生成(似乎Hasmany()和HasreQuired()不影响结果模型):
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Examination>("Examinations");
modelBuilder.EntitySet<Variable>("Variables");
modelBuilder.Entity<Examination>().HasMany(e => e.Variables);
modelBuilder.Entity<Variable>().HasRequired(v => v.Examination);
return modelBuilder.GetEdmModel();
产生的模型:
<EntityType Name="Examination">
<NavigationProperty Name="Variables" Relationship="YoStat.Models.YoStat_Models_Examination_Variables_YoStat_Models_Variable_VariablesPartner" ToRole="Variables" FromRole="VariablesPartner"/>
</EntityType>
<EntityType Name="Variable" Abstract="true">
<NavigationProperty Name="Examination" Relationship="YoStat.Models.YoStat_Models_Variable_Examination_YoStat_Models_Examination_ExaminationPartner" ToRole="Examination" FromRole="ExaminationPartner"/>
</EntityType>
<Association Name="YoStat_Models_Examination_Variables_YoStat_Models_Variable_VariablesPartner">
<End Type="YoStat.Models.Variable" Role="Variables" Multiplicity="*"/>
<End Type="YoStat.Models.Examination" Role="VariablesPartner" Multiplicity="0..1"/>
</Association>
<Association Name="YoStat_Models_Variable_Examination_YoStat_Models_Examination_ExaminationPartner">
<End Type="YoStat.Models.Examination" Role="Examination" Multiplicity="1"/>
<End Type="YoStat.Models.Variable" Role="ExaminationPartner" Multiplicity="0..1"/>
</Association>
<EntityContainer Name="Container">
<EntitySet Name="Examinations" EntityType="YoStat.Models.Examination"/>
<EntitySet Name="Variables" EntityType="YoStat.Models.Variable"/>
<AssociationSet Name="YoStat_Models_Examination_Variables_YoStat_Models_Variable_VariablesPartnerSet" Association="YoStat.Models.YoStat_Models_Examination_Variables_YoStat_Models_Variable_VariablesPartner">
<End Role="VariablesPartner" EntitySet="Examinations"/>
<End Role="Variables" EntitySet="Variables"/>
</AssociationSet>
<AssociationSet Name="YoStat_Models_Variable_Examination_YoStat_Models_Examination_ExaminationPartnerSet" Association="YoStat.Models.YoStat_Models_Variable_Examination_YoStat_Models_Examination_ExaminationPartner">
<End Role="ExaminationPartner" EntitySet="Variables"/>
<End Role="Examination" EntitySet="Examinations"/>
</AssociationSet>
</EntityContainer>
您可以看到,它会生成两个不同的关联,而不是一个。如何修复它?谢谢!
这看起来像是ODATA模型构建器中的一个错误,它总是为每个导航属性创建单向导航,而更好的方法是研究模型以检查是否是双向导航。我在:http://aspnetwebstack.codeplex.com/workitem/623
上提交了错误但是,我没有发现当前行为的客户端破裂。WCF DS客户端仍将生成正确的代理类。您是否有任何特定的用户场景被它阻止?该信息将帮助该错误更好地分类。谢谢。