Example #1
0
        private static IEdmModel getEdmModel()
        {
            ODataConventionModelBuilder      modelBuilder    = new ODataConventionModelBuilder();
            EntitySetConfiguration <Person>  peopleEntitySet = modelBuilder.EntitySet <Person>("People");
            EntityTypeConfiguration <Person> personType      = peopleEntitySet.EntityType;

            personType.Ignore(p => p.CreatedTime);
            personType.Ignore(p => p.LastModifiedTime);

            EntitySetConfiguration <Account>  accountEntitySet = modelBuilder.EntitySet <Account>("Accounts");
            EntityTypeConfiguration <Account> accountType      = accountEntitySet.EntityType;

            accountType.Ignore(a => a.LastModifyTime);
            accountType.Ignore(a => a.CreateTime);

            FunctionConfiguration getPersonAndDescendants = modelBuilder.Function("GetPersonAndDescendants");

            getPersonAndDescendants.ReturnsFromEntitySet <Person>("People");
            getPersonAndDescendants.Parameter <long>("Id");          // The id of the root person.
            getPersonAndDescendants.Parameter <long>("TotalLevels"); // How many levels will be loaded and the root person is included.
            getPersonAndDescendants.IsComposable = true;

            FunctionConfiguration getPersonAndAncestors = modelBuilder.Function("GetPersonAndAncestors");

            getPersonAndAncestors.ReturnsCollectionFromEntitySet <Person>("People");
            getPersonAndAncestors.Parameter <long>("Id");          // The id of the root person.
            getPersonAndAncestors.Parameter <long>("TotalLevels"); // How many levels will be loaded and the root person is included.
            getPersonAndAncestors.IsComposable = true;

            modelBuilder.Namespace = typeof(Person).Namespace;
            return(modelBuilder.GetEdmModel());
        }
        void ConfigureCatalogItem(EntityTypeConfiguration <CatalogItem> builder)
        {
            builder.ToTable("Catalog");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
            .IsRequired();

            builder.Property(ci => ci.Name)
            .IsRequired()
            .HasMaxLength(50);

            builder.Property(ci => ci.Price)
            .IsRequired();

            builder.Property(ci => ci.PictureFileName);


            builder.Ignore(ci => ci.PictureUri);
            builder.Ignore(ci => ci.TempImageName);

            builder.HasRequired <CatalogBrand>(ci => ci.CatalogBrand)
            .WithMany()
            .HasForeignKey(ci => ci.CatalogBrandId);

            builder.HasRequired <CatalogType>(ci => ci.CatalogType)
            .WithMany()
            .HasForeignKey(ci => ci.CatalogTypeId);
        }
Example #3
0
        /// <summary>
        /// Configure the mapping of database tables to entities
        /// </summary>
        /// <param name="modelBuilder"><see cref="System.Data.Entity.DbModelBuilder"/></param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            // Author mapping
            EntityTypeConfiguration <Author> author = modelBuilder.Entity <Author>();

            author.ToTable("authors");
            author.Property(a => a.AuthorID).HasColumnName("au_id");
            author.Property(a => a.FirstName).HasColumnName("au_fname");
            author.Property(a => a.LastName).HasColumnName("au_lname");
            author.Ignore(a => a.Name);
            author.Property(a => a.PhoneNumber).HasColumnName("phone");
            author.Property(a => a.Address).HasColumnName("address");
            author.Property(a => a.City).HasColumnName("city");
            author.Property(a => a.State).HasColumnName("state");
            author.Property(a => a.PostalCode).HasColumnName("zip");
            author.Property(a => a.HasContract).HasColumnName("contract");
            author.Ignore(a => a.YearToDateSales);
            author.HasKey(a => a.AuthorID);

            // Publisher mapping
            EntityTypeConfiguration <Publisher> publisher = modelBuilder.Entity <Publisher>();

            publisher.ToTable("publishers");
            publisher.Property(p => p.PublisherID).HasColumnName("pub_id");
            publisher.Property(p => p.Name).HasColumnName("pub_name");
            publisher.Property(p => p.City).HasColumnName("city");
            publisher.Property(p => p.State).HasColumnName("state");
            publisher.Property(p => p.Country).HasColumnName("country");
            publisher.Ignore(p => p.YearToDateSales);
            publisher.HasKey(p => p.PublisherID);

            // Title mapping
            EntityTypeConfiguration <Title> title = modelBuilder.Entity <Title>();

            title.ToTable("titles");
            title.Property(t => t.TitleID).HasColumnName("title_id");
            title.Property(t => t.BookTitle).HasColumnName("title");
            title.Property(t => t.Type).HasColumnName("type");
            title.Property(t => t.Price).HasColumnName("price");
            title.Property(t => t.Advance).HasColumnName("advance");
            title.Property(t => t.Royalty).HasColumnName("royalty");
            title.Property(t => t.YearToDateSales).HasColumnName("ytd_sales");
            title.Property(t => t.Notes).HasColumnName("notes");
            title.Property(t => t.PublishDate).HasColumnName("pubdate");
            title.HasRequired(t => t.Publisher).WithMany(p => p.Titles).Map(pt => pt.MapKey("pub_id"));
            title.HasMany(t => t.Authors).WithMany(a => a.Titles).Map(at => { at.ToTable("titleauthor"); at.MapLeftKey("title_id"); at.MapRightKey("au_id"); });
            title.HasKey(t => t.TitleID);
        }
Example #4
0
 protected OrderDbObjectMap(DbModelBuilder builder)
 {
     Map = builder.Entity <TObject>();
     Map.ToTable(typeof(TObject).Name);
     Map.HasKey(o => o.Id);
     Map.Ignore(o => o.IsNew);
 }
Example #5
0
 public LeadBuilder(EntityTypeConfiguration <Lead> builder)
 {
     builder.Property(b => b.Owner).HasMaxLength(100);
     builder.Ignore(b => b.FullName);
     builder.Property(b => b.FirstName).HasMaxLength(50).IsRequired();
     builder.Property(b => b.LastName).HasMaxLength(50);
     builder.Property(b => b.Company).HasMaxLength(100);
     builder.Property(b => b.Title).HasMaxLength(100);
     builder.Property(b => b.Telephone).HasMaxLength(20);
     builder.Property(b => b.MobilePhone).HasMaxLength(20);
     builder.Property(b => b.Email).HasMaxLength(100);
     builder.Property(b => b.Fax).HasMaxLength(20);
     builder.Property(b => b.Website).HasMaxLength(100);
     builder.Property(b => b.SkypeId).HasMaxLength(100);
     builder.Property(b => b.Twitter).HasMaxLength(100);
     builder.Property(b => b.SecondaryEmail).HasMaxLength(100);
     builder.Property(b => b.Photo).HasMaxLength(200);
     builder.Property(b => b.Address).HasMaxLength(500);
     builder.Property(b => b.PostalCode).HasMaxLength(10);
     builder.Property(b => b.Description).HasMaxLength(4000);
     builder.Property(b => b.Company).HasMaxLength(100).IsRequired();
     builder.HasOptional(p => p.LeadSource).WithMany(w => w.Leads).HasForeignKey(p => p.LeadSourceId);
     builder.HasOptional(p => p.Sector).WithMany(w => w.Leads).HasForeignKey(p => p.SectorId);
     builder.HasOptional(p => p.LeadStatus).WithMany(w => w.Leads).HasForeignKey(p => p.LeadStatusId);
     builder.HasOptional(p => p.Country).WithMany(w => w.Leads).HasForeignKey(p => p.CountryId);
     builder.HasOptional(p => p.City).WithMany(w => w.Leads).HasForeignKey(p => p.CityId);
     builder.HasOptional(p => p.Region).WithMany(w => w.Leads).HasForeignKey(p => p.RegionId);
 }
Example #6
0
        /// <summary>
        /// Ignores the catel properties for database mappings.
        /// </summary>
        /// <typeparam name="TEntity">The type of the t entity.</typeparam>
        /// <param name="configuration">The configuration.</param>
        /// <returns>EntityTypeConfiguration&lt;TEntity&gt;.</returns>
        public static EntityTypeConfiguration <TEntity> IgnoreCatelProperties <TEntity>(this EntityTypeConfiguration <TEntity> configuration)
            where TEntity : ModelBase
        {
            //configuration.Ignore(x => x.BusinessRuleErrorCount);
            //configuration.Ignore(x => x.BusinessRuleWarningCount);
            //configuration.Ignore(x => x.FieldErrorCount);
            //configuration.Ignore(x => x.FieldWarningCount);
            //configuration.Ignore(x => x.HasErrors);
            //configuration.Ignore(x => x.HasWarnings);
            configuration.Ignore(x => x.IsDirty);
            //configuration.Ignore(x => x.IsInEditSession);
            configuration.Ignore(x => x.IsReadOnly);
            //configuration.Ignore(x => x.Mode);
            //configuration.Ignore(x => x.ValidationContext);
            //configuration.Ignore(x => x.Validator);

            return(configuration);
        }
Example #7
0
        public void Cloning_an_entity_configuration_clones_its_ignored_properties()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mockProperty1 = new MockPropertyInfo(typeof(int), "P1");

            configuration.Ignore(mockProperty1);

            var clone = configuration.Clone();

            Assert.True(clone.IgnoredProperties.Contains(mockProperty1));

            var mockProperty2 = new MockPropertyInfo(typeof(int), "P2");

            configuration.Ignore(mockProperty2);

            Assert.False(clone.IgnoredProperties.Contains(mockProperty2));
        }
Example #8
0
 public AuditTrailChangeLogBuilder(EntityTypeConfiguration <AuditTrailChangeLogEntity> modelBuilder)
 {
     modelBuilder.ToTable(TableName);
     modelBuilder.HasKey(b => b.Id);
     modelBuilder.Property(b => b.ColumnName);
     modelBuilder.Property(b => b.ValueBefore);
     modelBuilder.Property(b => b.ValueAfter);
     modelBuilder.Ignore(b => b.Changed);
 }
        public static void Map(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <User> userConfig = modelBuilder.Entity <User>();

            userConfig.HasKey(u => u.Id);
            userConfig.Property(u => u.FirstName).IsRequired().HasMaxLength(50);
            userConfig.Property(u => u.LastName).IsRequired().HasMaxLength(50);
            userConfig.Ignore(u => u.FullName);
            userConfig.Property(u => u.Username).IsRequired().HasMaxLength(50);
            userConfig.Property(u => u.Password).IsRequired().HasMaxLength(50);
        }
Example #10
0
 private static void SuppressTrinityRdf <T>(EntityTypeConfiguration <T> entity) where T : ODataResource
 {
     entity.Ignore(v => v.IsDisposed);
     entity.Ignore(v => v.IsNew);
     entity.Ignore(v => v.IsBlank);
     entity.Ignore(v => v.IsSynchronized);
     entity.Ignore(v => v.Language);
     entity.Ignore(v => v.Model);
     entity.Ignore(v => v.Uri);
 }
        /// <summary>
        /// Takes care of setting up type configuration specific to the IBase model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="entityName">Name of the entity. used for automated index naming</param>
        /// <returns></returns>
        public static EntityTypeConfiguration <T> ApplyIBaseConfiguration <T>(this EntityTypeConfiguration <T> entity, string entityName) where T : class, IBase
        {
            entity.HasKey(t => t.Uuid);

            entity.Property(en => en.Uuid).HasColumnName("uuid");
            entity.Property(en => en.CreatedBy).HasColumnName("created_by");
            entity.Property(en => en.LastModifiedBy).HasColumnName("last_modified_by");
            entity.Property(en => en.CreateDateUtc).HasColumnName("create_date_utc");
            entity.Property(en => en.ModifyDateUtc).HasColumnName("modify_date_utc");
            entity.Property(en => en.EndDateUtc).HasColumnName("end_date_utc");

            entity.Ignore(p => p.TypeUuid);
            entity.Ignore(p => p.Links);
            entity.Ignore(p => p.LinkData);

            entity.Property(en => en.CreateDateUtc)
            .HasColumnAnnotation(
                "Index",
                new IndexAnnotation(new IndexAttribute($"idx_create_date_{entityName.ToLower()}")));

            return(entity);
        }
Example #12
0
        /// <summary>
        /// 映射属性
        /// </summary>
        /// <param name="builder"></param>
        protected override void MapProperties(EntityTypeConfiguration <Login> builder)
        {
            base.MapProperties(builder);

            builder.Property(t => t.Id).HasColumnName("LoginID");

            builder.Property(t => t.CreatorId).HasColumnName("Creater");
            builder.Property(t => t.CreationTime).HasColumnName("CreateTime");
            builder.Property(t => t.LastModifierId).HasColumnName("Editor");
            builder.Property(t => t.LastModificationTime).HasColumnName("EditTime");

            builder.Ignore(t => t.Version);
        }
Example #13
0
        public override void Build(EntityTypeConfiguration <User> configuration)
        {
            configuration.HasKey(x => x.ID);
            configuration.Property(x => x.ID).HasColumnName("UserID");
            configuration.Property(x => x.Name).HasColumnName("UserName");
            configuration.Property(x => x.Salt).HasColumnName("PasswordSalt");
            configuration.Property(x => x.SecretQuestion).HasColumnName("SecretQuestion");
            configuration.Property(x => x.SecretAnswer).HasColumnName("SecretAnswer");
            configuration.HasRequired(x => x.Consumer).WithMany(x => x.Users).Map(m => m.MapKey("ConsumerID"));
            configuration.Ignore(x => x.IsAuthenticated);
            configuration.Ignore(x => x.Permissions);

            configuration.HasMany(x => x.Roles)
            .WithMany(x => x.Users)
            .Map(map =>
            {
                map.ToTable("UsersInRoles");
                map.MapLeftKey("UserID");
                map.MapRightKey("RoleID");
            });

            configuration.HasMany(x => x.Groups)
            .WithMany(x => x.Users)
            .Map(map =>
            {
                map.ToTable("UsersInGroups");
                map.MapLeftKey("UserID");
                map.MapRightKey("GroupID");
            });

            configuration.HasMany(x => x.Applications)
            .WithMany(x => x.Users)
            .Map(map =>
            {
                map.ToTable("UsersInApplications");
                map.MapLeftKey("UserID");
                map.MapRightKey("ApplicationID");
            });
        }
Example #14
0
 public CustomerBuilder(EntityTypeConfiguration <Customer> builder)
 {
     builder.Property(b => b.FirstName).HasMaxLength(50).IsRequired();
     builder.Property(b => b.LastName).HasMaxLength(50).IsRequired();
     builder.Ignore(b => b.FullName);
     builder.Property(b => b.MobilePhone).HasMaxLength(20).IsRequired();
     builder.Property(b => b.Email).HasMaxLength(100);
     builder.Property(b => b.Company).HasMaxLength(100).IsRequired();
     builder.Property(b => b.Address).HasMaxLength(4000);
     builder.HasOptional(p => p.Country).WithMany(w => w.Customers).HasForeignKey(p => p.CountryId);
     builder.HasOptional(p => p.City).WithMany(w => w.Customers).HasForeignKey(p => p.CityId);
     builder.Property(b => b.Photo).HasMaxLength(200);
 }
        public static ManyNavigationPropertyConfiguration <T, TTarget> HasManyPrivate <T, TTarget>(
            this EntityTypeConfiguration <T> mapper,
            Expression <Func <T, ICollection <TTarget> > > exp,
            NamingConventions?convention = null)
            where T : class
            where TTarget : class
        {
            mapper.Ignore(exp);
            dynamic expression = exp;
            string  columnName;

            ExpressionModifier.ToPrivate(ref expression, convention, out columnName);
            return(mapper.HasMany(expression));
        }
        public static DateTimePropertyConfiguration PrivateProperty <T>(
            this EntityTypeConfiguration <T> mapper,
            Expression <Func <T, DateTimeOffset?> > exp,
            NamingConventions?convention = null) where T : class
        {
            mapper.Ignore(exp);
            dynamic expression = exp;
            string  defaultColumnName;

            ExpressionModifier.ToPrivate(ref expression, convention, out defaultColumnName);
            DateTimePropertyConfiguration configuration = mapper.Property(expression);

            configuration.HasColumnName(defaultColumnName);
            return(configuration);
        }
Example #17
0
        /// <summary>
        /// Gets the model.
        /// </summary>
        /// <returns></returns>
        /// <seealso cref="http://stackoverflow.com/questions/24829422/handling-dates-with-odata-v4-ef6-and-web-api-v2-2"/>
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder       builder   = new ODataConventionModelBuilder();
            EntityTypeConfiguration <Address> titleType = builder.EntityType <Address>();

            //http://stackoverflow.com/questions/24829422/handling-dates-with-odata-v4-ef6-and-web-api-v2-2
            titleType.Ignore(t => t.ModifiedDate);
            //titleType.Property(t => t.EdmModifiedDate).Name = "ModifiedDate";


            builder.EntitySet <Address>("Addresses");

            builder.Namespace = typeof(Address).Namespace;

            return(builder.GetEdmModel());
        }
Example #18
0
        public static void IgnoreAllBut <TEntityType>(
            this EntityTypeConfiguration <TEntityType> entityTypeConfiguration, params string[] names)
            where TEntityType : class
        {
            var properties = typeof(TEntityType).GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var property in properties.Where(p => !names.Contains(p.Name)))
            {
                var parameter = Expression.Parameter(typeof(TEntityType), "e");

                dynamic expression
                    = Expression.Lambda(
                          Expression.Property(parameter, property),
                          parameter);

                entityTypeConfiguration.Ignore(expression);
            }
        }
Example #19
0
        private void MapCustomer(EntityTypeConfiguration <Customer> entity)
        {
            entity.Property(k => k.CustomerTypeId).HasColumnName("CustomerTypeID");

            entity.Property(k => k.InitialDate).HasColumnType("DATETIME").HasColumnName("InitialDate").IsOptional();

            entity.Property(k => k.PrimaryDestinationId).HasColumnName("PrimaryDesintation");

            entity.Property(k => k.SecondaryDestinationId).HasColumnName("SecondaryDestination");

            entity.Property(k => k.PrimaryActivityId).HasColumnName("PrimaryActivity");

            entity.Property(k => k.SecondaryActivityId).HasColumnName("SecondaryActivity");

            entity.Property(k => k.Notes);

            entity.Property(k => k.CustomerRowVersion).HasColumnName("RowVersion").IsRowVersion().IsConcurrencyToken(false);

            entity.HasOptional(k => k.PrimaryActivity).WithMany().HasForeignKey(k => k.PrimaryActivityId);

            entity.HasOptional(k => k.SecondaryActivity).WithMany().HasForeignKey(k => k.SecondaryActivityId);

            entity.HasOptional(k => k.PrimaryDestination).WithMany().HasForeignKey(k => k.PrimaryDestinationId);

            entity.HasOptional(k => k.SecondaryDestination).WithMany().HasForeignKey(k => k.SecondaryDestinationId);

            entity.Property(k => k.BirthDate).HasColumnType("DATETIME").IsOptional();

            entity.Property(k => k.HeightInches).IsOptional();

            entity.Property(k => k.WeightPounds).IsOptional();

            entity.Property(k => k.DietaryRestrictions).IsOptional();

            entity.HasMany(k => k.Reservations).WithRequired().HasForeignKey(k => k.CustomerId);

            entity.Ignore(k => k.CustomerType);

            entity.Map(m =>
            {
                m.Properties(c => new { c.BirthDate, c.HeightInches, c.WeightPounds, c.DietaryRestrictions });
                m.ToTable("ContactPersonalInfo");
            });
        }
Example #20
0
        public EmployeeBuilder(EntityTypeConfiguration <Employee> builder)
        {
            builder.Property(b => b.FirstName).HasMaxLength(100).IsRequired();
            builder.Property(b => b.LastName).HasMaxLength(100).IsRequired();
            builder.Ignore(b => b.FullName);
            builder.Property(b => b.Photo).HasMaxLength(200);
            builder.Property(b => b.IdentityNumber).HasMaxLength(11);
            builder.Property(b => b.Mobile).HasMaxLength(20).IsRequired();
            builder.Property(b => b.Nationality).HasMaxLength(100).IsRequired();
            builder.Property(b => b.Address).HasMaxLength(100).IsRequired();
            builder.HasOptional(a => a.Department).WithMany(b => b.Employees).HasForeignKey(a => a.DepartmentId);
            builder.HasOptional(a => a.Position).WithMany(b => b.Employees).HasForeignKey(a => a.PositionId);
            builder.Property(b => b.Title).HasMaxLength(4000).IsRequired();

            builder.HasOptional(a => a.Certificate).WithMany(b => b.Employees).HasForeignKey(a => a.CertificateId);
            builder.HasOptional(a => a.Country).WithMany(b => b.Employees).HasForeignKey(a => a.CountryId);
            builder.HasOptional(a => a.City).WithMany(b => b.Employees).HasForeignKey(a => a.CityId);
            builder.HasOptional(a => a.Region).WithMany(b => b.Employees).HasForeignKey(a => a.RegionId);
        }
Example #21
0
        private void MapUsuarios(DbModelBuilder modelBuilder)
        {
            EntityTypeConfiguration <Usuario> tabla = modelBuilder.Entity <Usuario>();

            tabla
            .ToTable("Usuarios")
            .HasKey(c => c.UsuarioID);

            tabla
            .Property(c => c.UsuarioID)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            tabla
            .Property(c => c.Nombre)
            .HasMaxLength(50);

            tabla
            .Property(c => c.Apellidos)
            .HasMaxLength(150);

            tabla
            .Property(c => c.Email)
            .HasMaxLength(250);

            tabla
            .Ignore(e => e.Id)
            .Ignore(e => e.UserName)
            .Ignore(e => e.ApellidosNombre);

            tabla
            .HasMany(e => e.Aplicaciones)
            .WithMany(c => c.Usuarios)
            .Map(c =>
            {
                c.ToTable("AplicacionesUsuarios");
                c.MapLeftKey("UsuarioID");
                c.MapRightKey("AplicacionID");
            });

            tabla.HasRequired(c => c.Rol)
            .WithMany()
            .HasForeignKey(u => u.RolID);
        }
Example #22
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.HasDefaultSchema("word");

            EntityTypeConfiguration <Question> cardboxConfiguration = modelBuilder.Entity <Question>();

            cardboxConfiguration.HasKey(x => x.Id);
            cardboxConfiguration.HasRequired(x => x.Cardbox);
            cardboxConfiguration.Property(x => x.Text).IsRequired().HasColumnType("nvarchar").HasMaxLength(15);
            cardboxConfiguration.Property(x => x.QuestionType).IsRequired();
            cardboxConfiguration.Property(x => x.DateAddedValue).IsRequired().HasColumnType("date");
            cardboxConfiguration.Ignore(x => x.DateAdded);

            EntityTypeConfiguration <Cardbox> cardboxDefinitionConfiguration = modelBuilder.Entity <Cardbox>();

            cardboxDefinitionConfiguration.HasKey(x => x.Id);
            cardboxDefinitionConfiguration.Property(x => x.Duration).IsRequired();
            cardboxDefinitionConfiguration.Property(x => x.Number).IsRequired();
        }
Example #23
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Types().Configure(c => c.Ignore("IsDirty"));

            modelBuilder.Properties <Guid>().Where(p => p.Name == "Key").Configure(c => c.IsKey());

            var temp = new EntityTypeConfiguration <Person>();

            temp.Ignore(p => p.Customer);
            modelBuilder.Configurations.Add(temp);

            var cus = new CustomerConfigurations();

            modelBuilder.Configurations.Add(cus);

            modelBuilder.Conventions.Add(new TableSchemaAttributeConvention());

            modelBuilder.HasDefaultSchema("AnythingsBut_dbo");

            base.OnModelCreating(modelBuilder);
        }
Example #24
0
        private void MapContact(EntityTypeConfiguration <Contact> entity)
        {
            entity.HasKey(k => k.Id).ToTable("Contact");

            entity.Property(k => k.Id).HasColumnName("ContactID");

            entity.Property(k => k.FirstName).HasColumnName("FirstName");

            entity.Property(k => k.LastName).HasColumnName("LastName");

            entity.Property(k => k.Title).HasColumnName("Title");

            entity.Property(k => k.AddDate).HasColumnName("AddDate").HasColumnType("DATETIME");

            entity.Property(k => k.ModifiedDate).HasColumnName("ModifiedDate").HasColumnType("DATETIME");

            entity.Property(k => k.RowVersion).IsRowVersion();

            entity.Map <Customer>(m =>
            {
                m.Properties(c => new
                {
                    c.CustomerType,
                    c.InitialDate,
                    c.PrimaryActivityId,
                    c.PrimaryDestinationId,
                    c.SecondaryActivityId,
                    c.SecondaryDestinationId,
                    c.Notes,
                    c.CustomerRowVersion
                });
                m.ToTable("Customers");
            });

            entity.HasMany(k => k.Addresses).WithRequired(k => k.Contact).HasForeignKey(k => k.ContactId).WillCascadeOnDelete(true);

            entity.Ignore(k => k.FullName);
        }
Example #25
0
        public override void Build(EntityTypeConfiguration <Group> configuration)
        {
            configuration.HasKey(x => x.ID);
            configuration.Property(x => x.ID).HasColumnName("GroupID");
            configuration.HasRequired(x => x.Consumer).WithMany(x => x.Groups).Map(m => m.MapKey("ConsumerID"));
            configuration.Ignore(x => x.Permissions);
            configuration.HasMany(x => x.Roles)
            .WithMany(x => x.Groups)
            .Map(map =>
            {
                map.ToTable("RolesInGroups");
                map.MapLeftKey("GroupID");
                map.MapRightKey("RoleID");
            });

            configuration.HasMany(x => x.Users)
            .WithMany(x => x.Groups)
            .Map(map =>
            {
                map.ToTable("UsersInGroups");
                map.MapLeftKey("GroupID");
                map.MapRightKey("UserID");
            });
        }
Example #26
0
        public ContactBuilder(EntityTypeConfiguration <Contact> builder)
        {
            builder.Ignore(b => b.FullName);
            builder.Property(b => b.FirstName).HasMaxLength(50).IsRequired();
            builder.Property(b => b.LastName).HasMaxLength(50);
            builder.HasOptional(a => a.Company).WithMany(b => b.Contacts).HasForeignKey(a => a.CompanyId);
            builder.HasOptional(a => a.LeadSource).WithMany(b => b.Contacts).HasForeignKey(a => a.LeadSourceId);
            builder.HasOptional(a => a.ReportsToContact).WithMany(b => b.ChildContacts).HasForeignKey(a => a.ReportsToContactId);
            builder.HasOptional(a => a.Country).WithMany(b => b.PostalContacts).HasForeignKey(a => a.CountryId);
            builder.HasOptional(a => a.City).WithMany(b => b.PostalContacts).HasForeignKey(a => a.CityId);
            builder.HasOptional(a => a.Region).WithMany(b => b.PostalContacts).HasForeignKey(a => a.RegionId);
            builder.HasOptional(a => a.OtherCountry).WithMany(b => b.OtherContacts).HasForeignKey(a => a.OtherCountryId);
            builder.HasOptional(a => a.OtherCity).WithMany(b => b.OtherContacts).HasForeignKey(a => a.OtherCityId);
            builder.HasOptional(a => a.OtherRegion).WithMany(b => b.OtherContacts).HasForeignKey(a => a.OtherRegionId);

            builder.Property(b => b.Owner).HasMaxLength(100);
            builder.Property(b => b.Email).HasMaxLength(100);
            builder.Property(b => b.Telephone).HasMaxLength(20);
            builder.Property(b => b.OtherPhone).HasMaxLength(20);
            builder.Property(b => b.HomePhone).HasMaxLength(20);
            builder.Property(b => b.MobilePhone).HasMaxLength(20);
            builder.Property(b => b.AssistantName).HasMaxLength(100);
            builder.Property(b => b.AssistantPhone).HasMaxLength(20);
            builder.Property(b => b.Title).HasMaxLength(100);
            builder.Property(b => b.Department).HasMaxLength(100);
            builder.Property(b => b.Fax).HasMaxLength(20);
            builder.Property(b => b.SkypeId).HasMaxLength(100);
            builder.Property(b => b.Twitter).HasMaxLength(100);
            builder.Property(b => b.SecondaryEmail).HasMaxLength(100);
            builder.Property(b => b.Photo).HasMaxLength(200);
            builder.Property(b => b.Address).HasMaxLength(500);
            builder.Property(b => b.PostalCode).HasMaxLength(10);
            builder.Property(b => b.OtherAddress).HasMaxLength(500);
            builder.Property(b => b.OtherPostalCode).HasMaxLength(10);
            builder.Property(b => b.Description).HasMaxLength(4000);
        }
 public static void IgnorePhone(this EntityTypeConfiguration <AppUser> source)
 {
     source
     .Ignore(m => m.PhoneNumber)
     .Ignore(m => m.PhoneNumberConfirmed);
 }
Example #28
0
 public override void Configure <TEntity>(EntityTypeConfiguration <TEntity> config)
 {
     config.HasKey(t => t.Id);
     config.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Ignore(t => t.IsActive);
 }
 private void ConfigurePerson(EntityTypeConfiguration<Person> person) {
     person.Ignore(p => p.PersonType);
     person.Property(p => p.CreatedBy).IsRequired();
     person.Property(p => p.CreatedOn).IsRequired();
 }
Example #30
0
        Alias <
            TEntity,
            T,
            TPropertyConfiguration>(
            EntityTypeConfiguration <TEntity> entityConfig,
            Expression <Func <TEntity, T> > realExpression,
            string aliasName,
            Func <Expression <Func <TEntity, T> >, TPropertyConfiguration>
            propertyConfigFunc,
            out PropertyInfo realInfo,
            out TPropertyConfiguration aliasConfig)
            where TEntity
        : class
            where TPropertyConfiguration
        : PrimitivePropertyConfiguration
        {
            Check.Required(entityConfig, "entityConfig");
            Check.Required(realExpression, "realExpression");
            Check.Required(aliasName, "aliasName");
            Check.Required(propertyConfigFunc, "propertyConfigFunc");

            //
            // First, tell EF not to map the real property.  This has the side-effect
            // of getting it to sanity-check the real property lambda for us.
            //
            entityConfig.Ignore(realExpression);

            //
            // Dig PropertyInfo and (possibly) conversion operator out of the real
            // property lambda
            //
            MethodInfo realConversion;

            EFUtilities.GetPropertyInfoAndConversionFromPropertyLambda(
                realExpression,
                out realInfo,
                out realConversion);

            string realName = realInfo.Name;
            Type   realType = realInfo.PropertyType;

            //
            // Get the alias PropertyInfo
            //
            var aliasInfo = EFUtilities.GetMappablePropertyInfo(
                typeof(TEntity),
                realType,
                aliasName);

            //
            // Build a lambda to the alias property, going through the same conversion
            // operator as the real one (if present)
            //
            var aliasExpression = EFUtilities.MakeLambdaToProperty <TEntity, T>(
                aliasInfo,
                realConversion);

            //
            // Tell EF to map the alias property to the real property's DB column
            //
            aliasConfig = propertyConfigFunc(aliasExpression);
            aliasConfig.HasColumnName(realName);

            //
            // Apply alias column settings from attributes on the real property
            //
            if (realInfo.GetCustomAttributes <RequiredAttribute>().Any())
            {
                aliasConfig.IsRequired();
            }

            //
            // Remember the property mapping so we can duplicate it when querying
            //
            lock (realToAlias)
                realToAlias[realInfo] = aliasInfo;
        }
 private void ConfigureMovie(EntityTypeConfiguration<Movie> movie) {
     movie.Property(p => p.CreatedBy).IsRequired();
     movie.Property(p => p.CreatedOn).IsRequired();
     movie.Ignore(m => m.Actors);
     movie.Ignore(m => m.Directors);
 }