0

To start with I'm really new into developing with C#, ASPNET, and MS SQL so perhaps I'm just missing a simple point here or missunterstood a basic concept so please have patience with me :)

I'm Using Visual Studio Web Deveoloper 2010 Express with .NET Framework 4 and MVC2 (Have to use this specific Version). I also have SQL Management Studio 10.5 where I created a simple Table enter image description here

Now I want to use this as an entity model so I created one in Visual Studio and added all Tables (including the ASPNET User Tables) and Stored Procedures.enter image description here

The Problem is the Result...

enter image description here

I expected to be able to navigate from Kunden(createdBy, modifiedBy) to the ASPNET User Table like i can access "Geschenk" from the "Kunden" Table. I thought I will have a single Property here and not 2 of them for the same reason. Of course I could just rename the Navigation Properties but I want to know whats the cause of this and whats the proper way to use aspnetusers in this case?

8
  • 1
    Your expectation is wrong. EF builds a unique navigation property for each foreign key reference. One of those properties is the mapping for the user record that created the Kunden record, and the other is the mapping for the user record of the last user that modified it. Commented Jun 10, 2016 at 7:54
  • I would also strongly recommend updating to the Community edition, as what you're using isn't supported at this point. Commented Jun 10, 2016 at 7:57
  • @TiesonT. So the Navigation property is not created for the same object its in the sql table but for the object it "links to" ? Commented Jun 10, 2016 at 8:12
  • Or is this just for m:n relations? Then how is the Name of the Property determited or why isnt createdBy and modifiedBy is used as Navigation Property? Commented Jun 10, 2016 at 8:21
  • Yes to the first, and I'm not sure what you mean by the second. The navigation property is named for the table/set that it links to, more or less. Probably should read this Commented Jun 10, 2016 at 8:37

1 Answer 1

1

Kunden has 2 FK references to the aspnet_Users table. One corresponds to the createdBy column and the other corresponds to the modifiedBy column. Consequently, a navigation property is generated for each. Imagine that different users had created and modified a single Kunden.

If only a single association were generated, which user would you expect the aspnet_Users association to retrieve? If you're expecting a collection of both, then how would you distinguish between the two?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.