Advertisement
uraharadono

MojContext

Jan 19th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Data.Entity;
  3. using System.Data.Entity.ModelConfiguration.Conventions;
  4. using FEF.Helper;
  5. using Rent_aCar_TravelAgency.Models;
  6.  
  7. namespace FEF.Data
  8. {
  9.     class MojContext : DbContext
  10.     {
  11.         public MojContext() : base("Name=MojConnectionString")
  12.         {
  13.            
  14.         }
  15.         public DbSet<Grad> Gradovi { set; get; }
  16.         public DbSet<Korisnik> Korisnici { set; get; }
  17.         public DbSet<Opstina> Opstine { set; get; }
  18.         public DbSet<Ponuda> Ponude { set; get; }
  19.         public DbSet<Putovanje> Putovanja { set; get; }
  20.         public DbSet<PutovanjeDetalji> PutovanjaDetalji { set; get; }
  21.         public DbSet<Rezervacija> Rezervacije { set; get; }
  22.         public DbSet<Servisi> Servisi { set; get; }
  23.         public DbSet<Status> Statusi { set; get; }
  24.         public DbSet<Ucinak> Ucinci { set; get; }
  25.         public DbSet<Uloga> Uloge { set; get; }
  26.         public DbSet<Uplata> Uplate { set; get; }
  27.         public DbSet<Utisak> Utisci { set; get; }
  28.         public DbSet<Vozac> Vozaci { set; get; }
  29.         public DbSet<Vozilo> Vozila { set; get; }
  30.         public DbSet<VozilaKategorije> VozilaKategorije { set; get; }
  31.         public DbSet<Zaposlenik> Zaposlenici { set; get; }
  32.  
  33.         protected override void OnModelCreating(DbModelBuilder modelBuilder)
  34.         {
  35.             base.OnModelCreating(modelBuilder);
  36.  
  37.  
  38.             modelBuilder.Entity<Korisnik>().HasOptional(x => x.Zaposlenik).WithRequired(x => x.Korisnik);
  39.             modelBuilder.Entity<Korisnik>().HasOptional(x => x.Vozac).WithRequired(x => x.Korisnik);
  40.  
  41.             //modelBuilder.Entity<Opstine>().HasOptional(x => x.Gradovi).WithRequired(x => x.GradID);
  42.            
  43.             //one-to-(zero or one)
  44.             //modelBuilder.Entity<Korisnik>().HasOptional(x => x.Student).WithRequired(x => x.Korisnik);
  45.             //modelBuilder.Entity<Korisnik>().HasOptional(x => x.Nastavnik).WithRequired(x => x.Korisnik);
  46.             //modelBuilder.Entity<Korisnik>().HasOptional(x => x.Referent).WithRequired(x => x.Korisnik);
  47.  
  48.  
  49.  
  50.  
  51.             //many-to-one
  52.             //modelBuilder.Entity<Smjer>().HasRequired(x => x.Fakultet).WithMany().HasForeignKey(x=>x.FakultetId);
  53.             //modelBuilder.Entity<UpisGodine>().HasRequired(x => x.Student).WithMany().HasForeignKey(x=>x.StudentId);
  54.             //modelBuilder.Entity<UpisGodine>().HasRequired(x => x.AkademskaGodina).WithMany().HasForeignKey(x=>x.AkademskaGodinaId);
  55.             //http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx
  56.         }
  57.      
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement