/// <summary> /// Configures a non-clustered index for this entity type. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="entityTypeConfiguration">The entity type configuration.</param> /// <param name="indexName">The name of the index.</param> /// <param name="propertySelector">Selects the property to be indexed.</param> /// <param name="additionalPropertySelectors">Selects additional properties to be added to the index.</param> /// <returns>The entity type configuration, for fluent chaining.</returns> public static EntityTypeConfiguration<TEntity> HasIndex<TEntity>( this EntityTypeConfiguration<TEntity> entityTypeConfiguration, string indexName, Func<EntityTypeConfiguration<TEntity>, PrimitivePropertyConfiguration> propertySelector, params Func<EntityTypeConfiguration<TEntity>, PrimitivePropertyConfiguration>[] additionalPropertySelectors) where TEntity : class { return entityTypeConfiguration.HasIndex(indexName, IndexOptions.Nonclustered, propertySelector, additionalPropertySelectors); }
public static void CreateModel(this EntityTypeConfiguration <Rule> config) { config.HasKey(r => r.Id); config .Property(r => r.Id) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); config.Property(r => r.Name) .HasMaxLength(500); config.HasIndex(r => new { r.Name, r.Direction, r.Profile }); }
static void ConfigureContinent(EntityTypeConfiguration <Continent> entity) { entity.Property(p => p.Name).IsUnicode(false).HasMaxLength(100); entity.HasIndex(e => e.Name); entity.Property(e => e.Name).IsConcurrencyToken(); entity .HasMany(c => c.Countries) .WithOptional(c => c.Continent) .HasForeignKey(c => c.ContinentId) .WillCascadeOnDelete(true); entity.MapToStoredProcedures(); }
static void ConfigureCity(EntityTypeConfiguration <City> entity) { entity.Property(p => p.Name) .IsUnicode(false) .HasMaxLength(100) .IsConcurrencyToken(); entity.HasIndex(e => e.Name); entity.Property(e => e.Name).IsConcurrencyToken(); entity .HasOptional(c => c.Province) .WithMany(p => p.Cities); entity .HasOptional(c => c.Country); entity.MapToStoredProcedures(); }
public static void ApplySqlModelConfig <TEntity>(this EntityTypeConfiguration <TEntity> builder, bool aggregateIdIsUnique = true) where TEntity : SqlReadModel { builder.HasKey(k => k.Id); builder.Property(p => p.AggregateId).HasMaxLength(255).IsRequired(); if (aggregateIdIsUnique) { builder.HasIndex(p => p.AggregateId).IsUnique(); } builder.Property(p => p.CreatedBy).HasMaxLength(255).IsRequired(); builder.Property(p => p.CreatedTime).IsRequired(); builder.Property(p => p.ModifiedBy).HasMaxLength(255); builder.Property(p => p.ModifiedTime); builder.Property(p => p.LastAggregateSequenceNumber).IsRequired(); }
public UserBuilder(EntityTypeConfiguration <UserEntity> modelBuilder) { modelBuilder.ToTable(TableName); modelBuilder.HasIndex(b => b.Id); modelBuilder.Property(b => b.Email).IsRequired().HasMaxLength(200); modelBuilder.Property(b => b.Name).IsRequired().HasMaxLength(200); modelBuilder .HasMany(user => user.Roles) .WithMany(role => role.Users) .Map(pivotTable => { pivotTable.MapLeftKey("UserId"); pivotTable.MapRightKey("RoleId"); pivotTable.ToTable("UserRole"); }); modelBuilder .HasMany(user => user.Projects) .WithMany(project => project.Users) .Map(pivotTable => { pivotTable.MapLeftKey("UserId"); pivotTable.MapRightKey("ProjectId"); pivotTable.ToTable("UserProject"); }); modelBuilder .HasMany(userEntity => userEntity.Companies) .WithMany(companyEntity => companyEntity.Users) .Map(pivotTable => { pivotTable.MapLeftKey("UserId"); pivotTable.MapRightKey("CompanyId"); pivotTable.ToTable("UserCompany"); }); }
public LicenseBuilder(EntityTypeConfiguration <LicenseEntity> modelBuilder) { modelBuilder.ToTable(TableName); modelBuilder.HasIndex(b => b.Id); }