Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ProductShop.Data
- {
- using System;
- using System.Data.Entity;
- using System.Linq;
- using ProductShop.Models;
- public class ProductShopContext : DbContext
- {
- public ProductShopContext()
- : base("name=ProductShopContext")
- {
- }
- public virtual IDbSet<User> Users { get; set; }
- public virtual IDbSet<Category> Categories { get; set; }
- public virtual IDbSet<Product> Products { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<User>().HasMany(u => u.Friends).WithMany().Map(
- m =>
- {
- m.MapLeftKey("UserId");
- m.MapRightKey("FriendId");
- m.ToTable("UserFriends");
- });
- modelBuilder.Entity<User>()
- .HasMany(u => u.Products)
- .WithOptional(p => p.User).Map(m => { m.MapKey("BuyerId"); });
- modelBuilder.Entity<User>()
- .HasMany(u => u.Products)
- .WithRequired(p => p.User)
- .Map(m =>
- {
- m.MapKey("SellerId");
- });
- base.OnModelCreating(modelBuilder);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement