none
General Question of EF use RRS feed

  • Question

  • Hi everyone, 

    I've got a general question about the use of EF in a specific scenario.

    I have got:

    A table containing Subscribers
    A table containing Events
    A table connecting these tables with some extra info (InvitationSent, InvitationRead, Attending)

    Importing this system in VS results in a Subscriber & Event Entity, and the Event entity has a collection of subscribers. The problem I have is that the extra info of the connecting table (SubscriberEvent) is apparently lost. Do I have a designflaw, or how should I fix it so that the extra field are added to the Subscriber class when calling the Event.Subscribers collection?

     

    Very much appreciated 

     

    Tuesday, January 3, 2012 12:05 PM

Answers

  • Yes, the table first existed without the extra fields, causing, I assume,  EF to think of it as a Junction / Bridge table/entity. 

    Updating the model from database doesn't help, no "new" tables show up in the dialog, however the refresh tab shows all tables, but refreshing doesn't help either. 

    I am going to try to delete and recreate the edmx file. I'll post if it changes something.

    kr, 

    Tobias

    Thursday, January 5, 2012 9:27 AM

All replies

  • Hi Tobias;

    It sounds like you are using Code First with Entity Framework 4.1 or 4.2. If you post you code model we can give you a solution. It is difficult to say what may be going on without seeing the classes that make up the model.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, January 3, 2012 2:36 PM
  • Actually no, I'm using Database first (simple 4.0  :) ) and I generated & pluralized entities based on tables. 

    And this generation is not producing fields or an entity for the SubscriberEvent table.

     

    What exactly do you mean by "post your code model" ? Which file would this be? 

     

    Thanks for your quick response.

    Tuesday, January 3, 2012 2:45 PM
  • Hi Tobias;

    Can you go into SQL Server Management Studio and script the three tables so I can see what they look like.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, January 3, 2012 2:57 PM
  • Generating using Mgmt Studio is quite long. So placed it on my FTP. 

    Link

    Tuesday, January 3, 2012 3:02 PM
  • Hi Tobias;

    To your question, "What exactly do you mean by "post your code model" ? Which file would this be?", In Code First you design the database schema in code and EF goes and creates the database on the server. Seeming that you are using Database First this is not happening.

    The tables looked OK to me so I took the info you posted and created the tables in my SQL server then in VS 2010 I created a EF model with those three tables and this is what it produced.

    In your EF designer are you stating that the SubscriberEvents table is completely missing? If possible can you post an image as above?

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, January 3, 2012 3:40 PM
  • Of course everything is a little more complex. 

    Situation Entity Framework
    Situation SQL Server

    Thanks for your assistance so far!

    Tobias

    Wednesday, January 4, 2012 9:37 AM
  • Hi Tobias;

    The only time this would happen is when SubscriberEvent table is defined in the database as a Junction / Bridge table which SubscriberEvent is currently not. When you first created the mode was the SubscriberEvent table defined with only two columns one for each as a foreign key to the tables Subscriber and the other to Event? If so have you update the model from the database since then to reflect the new columns?

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, January 4, 2012 6:48 PM
  • Yes, the table first existed without the extra fields, causing, I assume,  EF to think of it as a Junction / Bridge table/entity. 

    Updating the model from database doesn't help, no "new" tables show up in the dialog, however the refresh tab shows all tables, but refreshing doesn't help either. 

    I am going to try to delete and recreate the edmx file. I'll post if it changes something.

    kr, 

    Tobias

    Thursday, January 5, 2012 9:27 AM
  • So that did the trick.

    Everything works.

    Thanks for your help!

    Thursday, January 5, 2012 10:57 AM