当前位置: 首页>>代码示例>>C#>>正文


C# EntityTypeConfiguration.HasKey方法代码示例

本文整理汇总了C#中EntityTypeConfiguration.HasKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityTypeConfiguration.HasKey方法的具体用法?C# EntityTypeConfiguration.HasKey怎么用?C# EntityTypeConfiguration.HasKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntityTypeConfiguration的用法示例。


在下文中一共展示了EntityTypeConfiguration.HasKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        /// <summary>
        /// Figures out the key properties and marks them as Keys in the EDM model.
        /// </summary>
        /// <param name="entity">The entity type being configured.</param>
        /// <param name="model">The <see cref="ODataModelBuilder"/>.</param>
        public override void Apply(EntityTypeConfiguration entity, ODataConventionModelBuilder model)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }

            // Suppress the EntityKeyConvention if there is any key in EntityTypeConfiguration.
            if (entity.Keys.Any() || entity.EnumKeys.Any())
            {
                return;
            }

            // Suppress the EntityKeyConvention if base type has any key.
            if (entity.BaseType != null && entity.BaseType.Keys().Any())
            {
                return;
            }

            PropertyConfiguration key = GetKeyProperty(entity);
            if (key != null)
            {
                entity.HasKey(key.PropertyInfo);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:30,代码来源:EntityKeyConvention.cs

示例2: RegTo

 public void RegTo(ConfigurationRegistrar confRegistrar)
 {
     var r = new EntityTypeConfiguration<UserInfo>();
     r.ToTable("UserInfo");
     r.HasKey(p => p.AutoId);
     confRegistrar.Add<UserInfo>(r);
 }
开发者ID:EricOrYhj,项目名称:PinEveryThing,代码行数:7,代码来源:UserMap.cs

示例3: MapApiDataSource

 /// <summary>Defines the mapping information for the entity 'ApiDataSource'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapApiDataSource(EntityTypeConfiguration<ApiDataSource> config)
 {
     config.ToTable("ApiDataSource");
     config.HasKey(t => t.Id);
     config.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.SourceName).HasMaxLength(50).IsRequired();
     config.Property(t => t.SourceBaseUrl).HasMaxLength(200);
 }
开发者ID:justinrobinson,项目名称:ODataTest,代码行数:10,代码来源:SqlExpressNovemberModelBuilder.cs

示例4: MapMovieNotFound

 /// <summary>Defines the mapping information for the entity 'MovieNotFound'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieNotFound(EntityTypeConfiguration<MovieNotFound> config)
 {
     config.ToTable("MovieNotFound");
     config.HasKey(t => new { t.ItemId, t.ItemSource });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.ItemSource).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired();
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100);
     config.Property(t => t.ItemSearchYear);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
开发者ID:justinrobinson,项目名称:ODataTest,代码行数:14,代码来源:SqlExpressNovemberModelBuilder.cs

示例5: HandlerInfoConfiguration

        private EntityTypeConfiguration<HandlerRecord> HandlerInfoConfiguration()
        {
            var config = new EntityTypeConfiguration<HandlerRecord>();

            config.HasKey(handler => new { handler.MessageId, handler.MessageTypeCode, handler.HandlerTypeCode });
            config.Property(handler => handler.MessageId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(handler => handler.MessageTypeCode).IsRequired().HasColumnType("int");
            config.Property(handler => handler.HandlerTypeCode).HasColumnType("int");
            config.Property(handler => handler.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_handlers");

            return config;
        }
开发者ID:y2ket,项目名称:thinknet,代码行数:14,代码来源:ThinkNetDbContext.cs

示例6: SnapshotConfiguration

        private EntityTypeConfiguration<Snapshot> SnapshotConfiguration()
        {
            var config = new EntityTypeConfiguration<Snapshot>();

            config.HasKey(snapshot => new { snapshot.AggregateRootId, snapshot.AggregateRootTypeCode });
            config.Property(snapshot => snapshot.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(snapshot => snapshot.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(snapshot => snapshot.Version).HasColumnType("int");
            config.Property(snapshot => snapshot.Data).HasColumnType("varchar");
            config.Property(snapshot => snapshot.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_snapshots");

            return config;
        }
开发者ID:y2ket,项目名称:thinknet,代码行数:15,代码来源:ThinkNetDbContext.cs

示例7: EventDataConfiguration

        private EntityTypeConfiguration<Event> EventDataConfiguration()
        {
            var config = new EntityTypeConfiguration<Event>();

            config.HasKey(@event => new { @event.AggregateRootId, @event.AggregateRootTypeCode, @event.Version });
            config.Property(@event => @event.AggregateRootId).IsRequired().HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.AggregateRootTypeCode).IsRequired().HasColumnType("int");
            config.Property(@event => @event.Version).HasColumnType("int");
            config.Property(@event => @event.CorrelationId).HasColumnType("char").HasMaxLength(36);
            config.Property(@event => @event.Payload).HasColumnType("varchar");
            config.Property(@event => @event.Timestamp).HasColumnName("OnCreated").HasColumnType("datetime");

            config.ToTable("thinknet_events");

            return config;
        }
开发者ID:y2ket,项目名称:thinknet,代码行数:16,代码来源:ThinkNetDbContext.cs

示例8: Apply

        /// <summary>
        /// Figures out the key properties and marks them as Keys in the EDM model.
        /// </summary>
        /// <param name="entity">The entity type being configured.</param>
        /// <param name="model">The <see cref="ODataModelBuilder"/>.</param>
        public override void Apply(EntityTypeConfiguration entity, ODataModelBuilder model)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }

            // Try to figure out keys only if there is no base type.
            if (entity.BaseType == null)
            {
                PropertyConfiguration key = GetKeyProperty(entity);
                if (key != null)
                {
                    entity.HasKey(key.PropertyInfo);
                }
            }
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:22,代码来源:EntityKeyConvention.cs

示例9: buildCustomers

        protected void buildCustomers(EntityTypeConfiguration<Customer> customerEntity)
        {
            customerEntity
                .HasKey(x => x.customerID)
                .Property(x => x.name).IsRequired()
                .HasMaxLength(50);

            customerEntity
                .HasMany(x => x.orders)
                .WithRequired(x => x.customer)
                .HasForeignKey(x => x.customerID)
                .WillCascadeOnDelete();

            customerEntity
                .Property(x => x.timeStamp)
                .IsRequired();
        }
开发者ID:ziahamza,项目名称:Wirecraft,代码行数:17,代码来源:SqlDbContext.cs

示例10: MapMovieCreditResult

 /// <summary>Defines the mapping information for the entity 'MovieCreditResult'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieCreditResult(EntityTypeConfiguration<MovieCreditResult> config)
 {
     config.ToTable("MovieCreditResult");
     config.HasKey(t => new { t.ItemId, t.RowId });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100);
     config.Property(t => t.ApiUrl).HasMaxLength(200);
     config.Property(t => t.ResultNum);
     config.Property(t => t.Name).HasMaxLength(100);
     config.Property(t => t.Order);
     config.Property(t => t.CastId).HasColumnName("Cast_Id");
     config.Property(t => t.Character).HasMaxLength(100);
     config.Property(t => t.CreditId).HasColumnName("Credit_Id").HasMaxLength(50);
     config.Property(t => t.TmdId);
     config.Property(t => t.ProfilePath).HasColumnName("Profile_Path").HasMaxLength(200);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
开发者ID:justinrobinson,项目名称:ODataTest,代码行数:21,代码来源:SqlExpressNovemberModelBuilder.cs

示例11: configureEntity

        /// <summary>
        /// Configure LongShortUrl entityTypeConfiguration
        /// </summary>
        /// <param name="modelBuilder"></param>
        private static void configureEntity(EntityTypeConfiguration<LongShortUrl> entityTypeConfiguration)
        {
            entityTypeConfiguration.HasKey(e => e.Id);

            entityTypeConfiguration.Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            entityTypeConfiguration.Property(e => e.ShortUrlId).IsRequired().HasMaxLength(10);

            entityTypeConfiguration.Property(e => e.LongUrl).IsRequired().HasMaxLength(2000);

            entityTypeConfiguration.Property(e => e.CreatedDate).IsRequired();

            entityTypeConfiguration
                .HasMany(e => e.LongShortUrlUsers)
                .WithOptional()
                .HasForeignKey(e => e.LongShortUrlId)
                .WillCascadeOnDelete();

        }
开发者ID:aserplus,项目名称:itty-bitty-url,代码行数:23,代码来源:IttyBittyContext.cs

示例12: buildBlobs

        protected void buildBlobs(EntityTypeConfiguration<Blob> blobEntity)
        {
            blobEntity
                .HasKey(x => x.blobID);

            blobEntity
                .Property(x => x.data)
                .IsRequired();

            blobEntity
                .Property(x => x.name)
                .IsRequired()
                .HasMaxLength(500);

            blobEntity
                .Property(x => x.timeStamp)
                .IsRequired();

            blobEntity
                .Property(x => x.type)
                .IsRequired();
        }
开发者ID:ziahamza,项目名称:Wirecraft,代码行数:22,代码来源:SqlDbContext.cs

示例13: Configure_HasColumnName_using_configuration_can_be_overriden_using_api

        public void Configure_HasColumnName_using_configuration_can_be_overriden_using_api()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            var configuration = new EntityTypeConfiguration<UnitMeasure>();

            configuration.HasKey(u => u.UnitMeasureCode);
            configuration.Property(u => u.UnitMeasureCode).HasColumnName("Code");

            modelBuilder.Configurations.Add(configuration);

            modelBuilder.Entity<UnitMeasure>().Property(u => u.UnitMeasureCode).HasColumnName("UnitCode");

            var databaseMapping = BuildMapping(modelBuilder);
            databaseMapping.AssertValid();

            databaseMapping.Assert<UnitMeasure>("UnitMeasures").HasColumns("UnitCode", "Name");
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:18,代码来源:PropertyConfigurationScenarioTests.cs

示例14: MapMovieResult

 /// <summary>Defines the mapping information for the entity 'MovieResult'</summary>
 /// <param name="config">The configuration to modify.</param>
 protected virtual void MapMovieResult(EntityTypeConfiguration<MovieResult> config)
 {
     config.ToTable("MovieResult");
     config.HasKey(t => new { t.ItemId, t.ItemSource, t.RowId });
     config.Property(t => t.ItemId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.ItemSearchTitle).HasMaxLength(100).IsRequired();
     config.Property(t => t.ItemSource).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
     config.Property(t => t.RowId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
     config.Property(t => t.ItemSearchYear);
     config.Property(t => t.ApiUrl).HasMaxLength(200);
     config.Property(t => t.ResultTitle).HasMaxLength(100);
     config.Property(t => t.ResultYear);
     config.Property(t => t.IsMovie);
     config.Property(t => t.ResultCt);
     config.Property(t => t.Page);
     config.Property(t => t.TotalPages).HasColumnName("Total_Pages");
     config.Property(t => t.TotalResults).HasColumnName("Total_Results");
     config.Property(t => t.ResultNum);
     config.Property(t => t.GenreIds).HasColumnName("Genre_Ids").HasMaxLength(100);
     config.Property(t => t.OriginalLanguage).HasColumnName("Original_Language").HasMaxLength(50);
     config.Property(t => t.OriginalTitle).HasColumnName("Original_Title").HasMaxLength(100);
     config.Property(t => t.Overview);
     config.Property(t => t.ReleaseDate).HasColumnName("Release_Date").HasMaxLength(50);
     config.Property(t => t.PosterPath).HasColumnName("Poster_Path").HasMaxLength(250);
     config.Property(t => t.Popularity);
     config.Property(t => t.Video);
     config.Property(t => t.VoteAverage).HasColumnName("Vote_Average");
     config.Property(t => t.VoteCount).HasColumnName("Vote_Count");
     config.Property(t => t.Rated).HasMaxLength(50);
     config.Property(t => t.Released).HasMaxLength(50);
     config.Property(t => t.Runtime).HasMaxLength(50);
     config.Property(t => t.Genre).HasMaxLength(50);
     config.Property(t => t.Director).HasMaxLength(100);
     config.Property(t => t.Writer).HasMaxLength(100);
     config.Property(t => t.Actors);
     config.Property(t => t.Plot);
     config.Property(t => t.Language).HasMaxLength(50);
     config.Property(t => t.Country).HasMaxLength(50);
     config.Property(t => t.Awards).HasMaxLength(100);
     config.Property(t => t.Poster).HasMaxLength(200);
     config.Property(t => t.MetaScore).HasMaxLength(50);
     config.Property(t => t.ImdbRating).HasMaxLength(50);
     config.Property(t => t.ImdbVotes).HasMaxLength(50);
     config.Property(t => t.ImdbId).HasMaxLength(50);
     config.Property(t => t.Type).HasMaxLength(100);
     config.Property(t => t.Tmeter).HasColumnName("TMeter").HasMaxLength(100);
     config.Property(t => t.Timage).HasColumnName("TImage").HasMaxLength(200);
     config.Property(t => t.Trating).HasColumnName("TRating").HasMaxLength(50);
     config.Property(t => t.Treviews).HasColumnName("TReviews");
     config.Property(t => t.Tfresh).HasColumnName("TFresh").HasMaxLength(50);
     config.Property(t => t.Trotten).HasColumnName("TRotten").HasMaxLength(50);
     config.Property(t => t.Tconsensus).HasColumnName("TConsensus").HasMaxLength(50);
     config.Property(t => t.TuserMeter).HasColumnName("TUserMeter").HasMaxLength(50);
     config.Property(t => t.TuserRating).HasColumnName("TUserRating").HasMaxLength(50);
     config.Property(t => t.TuserReviews).HasColumnName("TUserReviews");
     config.Property(t => t.Dvd).HasColumnName("DVD").HasMaxLength(100);
     config.Property(t => t.BoxOffice).HasMaxLength(50);
     config.Property(t => t.Production).HasMaxLength(50);
     config.Property(t => t.Website).HasMaxLength(200);
     config.Property(t => t.Response).HasMaxLength(10);
     config.Property(t => t.AddedOn);
     config.Property(t => t.ChangedOn);
 }
开发者ID:justinrobinson,项目名称:ODataTest,代码行数:65,代码来源:SqlExpressNovemberModelBuilder.cs

示例15: buildOrders

        protected void buildOrders(EntityTypeConfiguration<Order> orderEntity)
        {
            orderEntity
                .HasKey(x => x.orderID)
                .Property(x => x.orderDate)
                .IsRequired();

            orderEntity
                .Property(x => x.status)
                .IsRequired();

            orderEntity
                .Property(x => x.address)
                .IsRequired()
                .HasMaxLength(400);

            orderEntity
                .Property(x => x.timeStamp)
                .IsRequired();

            orderEntity
                .HasRequired(x => x.customer)
                .WithMany(x => x.orders);
            orderEntity
                .HasMany(x => x.products)
                .WithRequired(x => x.order)
                .WillCascadeOnDelete();
        }
开发者ID:ziahamza,项目名称:Wirecraft,代码行数:28,代码来源:SqlDbContext.cs


注:本文中的EntityTypeConfiguration.HasKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。