Example #1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<Person>().ToTable("People");
            //modelBuilder.Entity<BankAccount>().ToTable("People");
            //modelBuilder.Entity<Person>().HasOne(c => c.BankAccount).WithOne(c => c.Person)
            //    .HasForeignKey<Person>(c => c.Id);
            //modelBuilder.Entity<Person>().OwnsOne(c => c.Home);
            modelBuilder.Entity <Person>().HasDiscriminator <int>("Split").HasValue <Person>(1)
            .HasValue <Teacher>(2);
            modelBuilder.HasDbFunction(() => DbFunction.MyFunction());

            modelBuilder.Entity <Person>().Property(c => c.Year)
            .HasComputedColumnSql("DatePart(yyyy,[BirthDate])");

            modelBuilder.Entity <Person>().Property(c => c.BirthDate).HasValueGenerator <DateTimeValueGenerator>();
            //modelBuilder.Entity<Person>().Property(c => c.BirthDate).HasDefaultValueSql("getdate()");

            //modelBuilder.HasSequence<int>("TestInt", c => {

            //    c.HasMin(12);
            //    c.IncrementsBy(2);

            //});

            //modelBuilder.Entity<Person>().Property(c => c.FirstName)
            //    .IsConcurrencyToken();
            modelBuilder.Entity <Person>().Property(c => c.Token).IsRowVersion();

            //modelBuilder.Entity<BankAccount>().Property(c => c.RowVersion).IsRowVersion();

            modelBuilder.Entity <Person>().HasData(

                new Person {
                BirthDate = DateTime.Now,
                FirstName = "1",
                LastName  = "2",

                Id = 1
            }

                );
        }