none
Entity framework code first releationship RRS feed

  • Question

  • I'm trying to set up a User and friends relationship.  How will one do that in EF code First?
    Friday, March 25, 2011 3:12 AM

Answers

All replies

  • Hi Game99,

    Welcome!

    Would you please clarify the relationship between User and friends. we can use Icollection<type>() to create the foreign relationship in EF.

    I think you can use Fluent API to create the relationship between the entities, you can refer here: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx

    modelBuilder.Entity<Product>() //one to many
      .HasRequired(p => p.PrimaryCategory) 
      .WithMany(c => c.Products) 
      .HasForeignKey(p => p.PrimaryCategoryCode);
    
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, March 25, 2011 5:46 AM
    Moderator
  • Hi Game99,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 29, 2011 2:43 PM
    Moderator