3

I'm starting to learn ASP.NET and I followed this tutorial. So, I got a simple app which uses the ASP.NET Identity membership system and has an additional database containing products and cart items.

Is there a way for creating a many-to-many relationship between the users and the products data, considering they belong to (I guess) two different databases? I also want to save the user who adds a new item, so I would need a many-to-one relationship or a foreign key. I found a bunch of tutorials specified for MVC, but none for Web Forms and since I'm a beginner I didn't manage to figure out how to implement that for my needs.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
van
  • 367
  • 4
  • 13
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Mar 07 '15 at 05:37
  • http://stackoverflow.com/questions/4452132/add-foreign-key-relationship-between-two-databases – Ewan Mar 07 '15 at 11:24
  • Thank you, but this solution doesn't use the entity framework – van Mar 07 '15 at 11:27
  • I hope I made it more clear [here](http://stackoverflow.com/questions/28914427/relationship-between-aspnetusers-identity-and-other-tables-in-a-database-enti) – van Mar 07 '15 at 11:42

1 Answers1

0

It stores every item added to the cart with no info about the user who added it, so every cart item is shown to every user who logs in.

Are you sure about this? Quote from the tutorial below:

If the user is signed in as a registered user, the cart ID is set to their user name. However, if the user is not signed in, the cart ID is set to a unique value (a GUID). A GUID ensures that only one cart is created for each user, based on session.

TAMTAM
  • 101
  • 5
  • I misunderstood that and I edited the question, but still I need to create these many-to-many and one-to-many relationships and it didn't help me to understand how can I do it. – van Mar 07 '15 at 01:41
  • Well you have a clue in section 8 of the tutorial (Membership and Administration): If you wish to store the membership data along with the product data, you can consider using the same DbContext that you used to store the product data in the above code. You can have the products and identity models in the same context and customize them as you wish. – TAMTAM Mar 07 '15 at 11:49
  • Where can I find more instructions on how to do this? – van Mar 07 '15 at 12:19
  • I suggest a EF tutorial: http://www.asp.net/web-forms/overview/older-versions-getting-started/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-1 – TAMTAM Mar 07 '15 at 12:27