• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# EntityTypeConfiguration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中EntityTypeConfiguration的典型用法代码示例。如果您正苦于以下问题:C# EntityTypeConfiguration类的具体用法?C# EntityTypeConfiguration怎么用?C# EntityTypeConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EntityTypeConfiguration类属于命名空间,在下文中一共展示了EntityTypeConfiguration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: NhsContext

 public NhsContext(EntityTypeConfiguration<Person> personTypeConfiguration,
     EntityTypeConfiguration<Colour> colourTypeConfiguration)
     : base("name=NhsContext")
 {
     _personTypeConfiguration = personTypeConfiguration;
     _colourTypeConfiguration = colourTypeConfiguration;
 }
开发者ID:jerzynaf,项目名称:WebApiTestFirstTry,代码行数:7,代码来源:NhsContext.cs


示例3: 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


示例4: Apply

 public override void Apply(EntityTypeConfiguration entity, ODataModelBuilder model)
 {
     if (entity.IsAbstract == null)
     {
         entity.IsAbstract = entity.ClrType.IsAbstract;
     }
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:AbstractEntityTypeDiscoveryConvention.cs


示例5: Can_get_and_set_table_name

        public void Can_get_and_set_table_name()
        {
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            entityTypeConfiguration.ToTable("Foo");

            Assert.Equal("Foo", entityTypeConfiguration.GetTableName().Name);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:7,代码来源:EntityTypeConfigurationTests.cs


示例6: GetDefaultNavigationSource

        private static NavigationSourceConfiguration GetDefaultNavigationSource(EntityTypeConfiguration targetEntityType,
            ODataModelBuilder model, bool isSingleton)
        {
            if (targetEntityType == null)
            {
                return null;
            }

            NavigationSourceConfiguration[] matchingNavigationSources = null;
            if (isSingleton)
            {
                matchingNavigationSources = model.Singletons.Where(e => e.EntityType == targetEntityType).ToArray();
            }
            else
            {
                matchingNavigationSources = model.EntitySets.Where(e => e.EntityType == targetEntityType).ToArray();
            }

            if (matchingNavigationSources.Length > 1)
            {
                return null;
            }
            else if (matchingNavigationSources.Length == 1)
            {
                return matchingNavigationSources[0];
            }
            else
            {
                // default navigation source is the same as the default navigation source for the base type.
                return GetDefaultNavigationSource(targetEntityType.BaseType as EntityTypeConfiguration,
                    model, isSingleton);
            }
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:33,代码来源:AssociationSetDiscoveryConvention.cs


示例7: ExpressionTranslator

        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="nameChanges"></param>
        internal ExpressionTranslator(EntityTypeConfiguration configuration)
        {
            //_nameChanges = nameChanges;
            _configuration = configuration;
            _nameChanges = configuration.KeyMappings;

            _constantEvaluator = new ExpressionEvaluator();
        }
开发者ID:s-innovations,项目名称:azure-table-storage-repository-pattern,代码行数:12,代码来源:ExpressionTranslator.cs


示例8: 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


示例9: Configure_should_throw_when_property_not_found

        public void Configure_should_throw_when_property_not_found()
        {
            var entityType = new EdmEntityType { Name = "E" };
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
            entityTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object);

            Assert.Equal(Strings.PropertyNotFound(("P"), "E"), Assert.Throws<InvalidOperationException>(() => entityTypeConfiguration.Configure(entityType, new EdmModel())).Message);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:9,代码来源:EntityTypeConfigurationTests.cs


示例10: Add_entity_configuration_should_add_to_model_configuration

        public void Add_entity_configuration_should_add_to_model_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var entityConfiguration = new EntityTypeConfiguration<object>();

            new ConfigurationRegistrar(modelConfiguration).Add(entityConfiguration);

            Assert.Same(entityConfiguration.Configuration, modelConfiguration.Entity(typeof(object)));
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:9,代码来源:ConfigurationRegistrarTests.cs


示例11: Configure_should_set_configuration

        public void Configure_should_set_configuration()
        {
            var entityType = new EdmEntityType { Name = "E" };
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));

            entityTypeConfiguration.Configure(entityType, new EdmModel());

            Assert.Same(entityTypeConfiguration, entityType.GetConfiguration());
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:9,代码来源:EntityTypeConfigurationTests.cs


示例12: GetTableName_returns_current_TableName

        public void GetTableName_returns_current_TableName()
        {
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));

            Assert.Equal(null, entityTypeConfiguration.GetTableName());

            entityTypeConfiguration.ToTable("Foo");
            Assert.Equal("Foo", entityTypeConfiguration.GetTableName().Name);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:9,代码来源:EntityTypeConfigurationTests.cs


示例13: Define

        internal static void Define(EntityTypeConfiguration<Domain.Transaction> config)
        {
            config.HasOptional(p => p.CreditedUser)
                .WithMany(r => r.Credits)
                .HasForeignKey(fk => fk.CreditedUserId);

            config.HasOptional(p => p.DebitedUser)
                .WithMany(r => r.Debits)
                .HasForeignKey(fk => fk.DebitedUserId);

            config.Property(p => p.Amount).HasPrecision(19, 4);
        }
开发者ID:RichardAllanBrown,项目名称:OctoBotSharp,代码行数:12,代码来源:TransactionMap.cs


示例14: Define

        internal static void Define(EntityTypeConfiguration<Domain.ItemInstance> config)
        {
            config.HasRequired(r => r.Item)
                .WithMany(r => r.OwnedBy)
                .HasForeignKey(fk => fk.ItemId)
                .WillCascadeOnDelete(false);

            config.HasRequired(r => r.Owner)
                .WithMany(r => r.Items)
                .HasForeignKey(fk => fk.OwnerId)
                .WillCascadeOnDelete(false);
        }
开发者ID:RichardAllanBrown,项目名称:OctoBotSharp,代码行数:12,代码来源:ItemInstanceMap.cs


示例15: 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


示例16: Configure_should_configure_entity_set_name

        public void Configure_should_configure_entity_set_name()
        {
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType { Name = "E" };
            var entitySet = model.AddEntitySet("ESet", entityType);

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)) { EntitySetName = "MySet" };

            entityTypeConfiguration.Configure(entityType, model);

            Assert.Equal("MySet", entitySet.Name);
            Assert.Same(entityTypeConfiguration, entitySet.GetConfiguration());
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:13,代码来源:EntityTypeConfigurationTests.cs


示例17: GetTranslators

 private static IEnumerable<IMethodTranslator> GetTranslators(EntityTypeConfiguration configuration)
 {
     return new List<IMethodTranslator>
         {
             new WhereTranslator(configuration),
             new FirstTranslator(configuration),
             new FirstOrDefaultTranslator(configuration),
             new SingleTranslator(configuration),
             new SingleOrDefaultTranslator(configuration),
             new SelectTranslator(configuration.KeyMappings),
             new TakeTranslator()
         };
 }
开发者ID:s-innovations,项目名称:azure-table-storage-repository-pattern,代码行数:13,代码来源:QueryTranslator.cs


示例18: GetKeyProperty

        private static PropertyConfiguration GetKeyProperty(EntityTypeConfiguration entityType)
        {
            IEnumerable<PropertyConfiguration> keys =
                entityType.Properties
                .Where(p => (p.Name.Equals(entityType.Name + "Id", StringComparison.OrdinalIgnoreCase) || p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase))
                && EdmLibHelpers.GetEdmPrimitiveTypeOrNull(p.PropertyInfo.PropertyType) != null);

            if (keys.Count() == 1)
            {
                return keys.Single();
            }

            return null;
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:14,代码来源:EntityKeyConvention.cs


示例19: 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


示例20: TimestampConvention_AppliesWhenTheAttributeIsAppliedToASingleProperty

        public void TimestampConvention_AppliesWhenTheAttributeIsAppliedToASingleProperty()
        {
            // Arrange
            PropertyInfo property = CreateMockPropertyInfo("TestProperty");
            EntityTypeConfiguration entityType = new EntityTypeConfiguration();
            PrimitivePropertyConfiguration primitiveProperty = new PrimitivePropertyConfiguration(property, entityType);
            entityType.ExplicitProperties.Add(property, primitiveProperty);
            TimestampAttributeEdmPropertyConvention convention = new TimestampAttributeEdmPropertyConvention();

            // Act
            convention.Apply(primitiveProperty, entityType);

            // Assert
            Assert.True(primitiveProperty.ConcurrencyToken);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:15,代码来源:TimestampAttributeEdmPropertyConventionTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Entry类代码示例发布时间:2022-05-24
下一篇:
C# EntityType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap