Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 0.46 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Relationship Using Code first with Existing database
  2. public class Product
  3.     {
  4.         public int ProductId { get; set; }
  5.         public string Name { get; set; }
  6.         public Category Category { get; set; }
  7.     }
  8.  
  9.     public class Category
  10.     {
  11.         public int CategoryId { get; set; }
  12.         public string Name { get; set; }
  13.         public ICollection<Product> Products { get; set; }
  14.     }
  15.        
  16. modelBuilder.Entity<Product>()
  17.     .HasMany(x => x.Category)