Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8813969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:59:31+00:00 2026-06-14T03:59:31+00:00

I have two related entities (I’ve added all possible data annotations, but it seems

  • 0

I have two related entities (I’ve added all possible data annotations, but it seems that ODataConventionModelBuilder ignores them):

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; }
}

Here is an OData model generation (it seems, that HasMany() and HasRequired() doesn’t affect resulting model):

        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();

Resulting model:

<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>

As you can see, it generates two distinct associations instead of one. How to fix it? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:59:32+00:00Added an answer on June 14, 2026 at 3:59 am

    This looks like a bug in odata model builder, which always creates unidirectional navigation for each navigation property, while the better way is to look into the model to check if it’s a bidirectional navigation first. I filed the bug at: http://aspnetwebstack.codeplex.com/workitem/623

    However, I didn’t find anything broken in client side with current behavior. WCF DS client will still generate correct proxy classes. Do you have any specific user scenario which is blocked by it? The information will help the bug to be better triaged. Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using core data in my app. I have two entities that are related:
I have two tables that are not related using a foreign key but should
I have two related entities being mapped by JPA annotations backed by hibernate. The
Say I have two entities in Doctrine2 that are related to each other, Models\User
I have two entities A and B that are related in a MxN relation
I have two entities - UserObj and Producer. UserObj stores user-related profile data Producer
.NET 4, EF 4 I have two related entities, Order and OrderLine. Order contains
I have two related entities. Fruits.Apple Cars.Bmw Those entities belongs to the same user
I have two related entities, say @Entity public class Book { @ManyToOne Shelf shelf;
I have two related one to many entities Race and Cars (on race contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.