本文整理汇总了C#中Microsoft.EntityFrameworkCore.Metadata.Internal.Model类的典型用法代码示例。如果您正苦于以下问题:C# Model类的具体用法?C# Model怎么用?C# Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于Microsoft.EntityFrameworkCore.Metadata.Internal命名空间,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_set_ClrType
public void Can_set_ClrType()
{
var entityType = new Model().AddEntityType(typeof(object));
var property = entityType.AddProperty("Kake", typeof(string));
Assert.Equal(typeof(string), property.ClrType);
}
示例2: Delegate_getter_is_returned_for_IProperty_property
public void Delegate_getter_is_returned_for_IProperty_property()
{
var entityType = new Model().AddEntityType(typeof(Customer));
var idProperty = entityType.AddProperty("Id", typeof(int), shadow: false);
Assert.Equal(7, new ClrPropertyGetterFactory().Create(idProperty).GetClrValue(new Customer { Id = 7 }));
}
示例3: Change_tracking_strategy_can_be_changed
public void Change_tracking_strategy_can_be_changed()
{
var model = new Model { ChangeTrackingStrategy = ChangeTrackingStrategy.ChangingAndChangedNotifications };
Assert.Equal(ChangeTrackingStrategy.ChangingAndChangedNotifications, model.ChangeTrackingStrategy);
model.ChangeTrackingStrategy = ChangeTrackingStrategy.ChangedNotifications;
Assert.Equal(ChangeTrackingStrategy.ChangedNotifications, model.GetChangeTrackingStrategy());
}
示例4: Model_can_be_set_explicitly_in_options
public void Model_can_be_set_explicitly_in_options()
{
var model = new Model();
var optionsBuilder = new DbContextOptionsBuilder().UseModel(model);
Assert.Same(model, optionsBuilder.Options.FindExtension<CoreOptionsExtension>().Model);
}
示例5: Can_get_model
public void Can_get_model()
{
var model = new Model();
var sequence = Sequence.GetOrAddSequence(model, RelationalFullAnnotationNames.Instance.SequencePrefix, "Foo");
Assert.Same(model, sequence.Model);
}
示例6: CreateForeignKey
private ForeignKey CreateForeignKey()
{
var model = new Model();
var entityType = model.AddEntityType(typeof(E));
var idProperty = entityType.AddProperty("id", typeof(int));
var key = entityType.SetPrimaryKey(idProperty);
var fkProperty = entityType.AddProperty("p", typeof(int));
return entityType.AddForeignKey(fkProperty, key, entityType);
}
示例7: M_underscore_matching_field_is_not_used_if_type_is_not_compatible
public void M_underscore_matching_field_is_not_used_if_type_is_not_compatible()
{
var entityType = new Model().AddEntityType(typeof(TheDarkSideOfTheMoon));
var property = entityType.AddProperty("SpeakToMe", typeof(int), shadow: false);
var propertyInfo = entityType.ClrType.GetAnyProperty("SpeakToMe");
var fields = propertyInfo.DeclaringType.GetRuntimeFields().ToDictionary(f => f.Name);
Assert.Null(new FieldMatcher().TryMatchFieldName(property, propertyInfo, fields));
}
示例8: Sensitive_data_logging_can_be_set_explicitly_in_options
public void Sensitive_data_logging_can_be_set_explicitly_in_options()
{
var model = new Model();
var optionsBuilder = new DbContextOptionsBuilder().UseModel(model).EnableSensitiveDataLogging();
Assert.Same(model, optionsBuilder.Options.FindExtension<CoreOptionsExtension>().Model);
Assert.True(optionsBuilder.Options.FindExtension<CoreOptionsExtension>().IsSensitiveDataLoggingEnabled);
}
示例9: Constructor_validates_properties_from_same_entity
public void Constructor_validates_properties_from_same_entity()
{
var property1 = new Model().AddEntityType(typeof(Customer)).GetOrAddProperty(Customer.IdProperty);
var property2 = new Model().AddEntityType(typeof(Order)).GetOrAddProperty(Order.IdProperty);
Assert.Equal(CoreStrings.IndexPropertiesWrongEntity($"{{'{property1.Name}', '{property2.Name}'}}", typeof(Customer).Name),
Assert.Throws<InvalidOperationException>(
() => property1.DeclaringEntityType.AddIndex(new[] { property1, property2 })).Message);
}
示例10: Does_not_detect_duplicate_table_names_for_inherited_entities
public virtual void Does_not_detect_duplicate_table_names_for_inherited_entities()
{
var model = new Model();
var entityA = model.AddEntityType(typeof(A));
SetPrimaryKey(entityA);
var entityC = model.AddEntityType(typeof(C));
SetBaseType(entityC, entityA);
Validate(model);
}
示例11: Throws_if_no_match_found_and_no_property_setter
public void Throws_if_no_match_found_and_no_property_setter()
{
var entityType = new Model().AddEntityType(typeof(TheDarkSide));
var property = entityType.AddProperty(TheDarkSide.TimeProperty);
Assert.Equal(
CoreStrings.NoFieldOrSetter(typeof(TheDarkSide).FullName, "Time"),
Assert.Throws<InvalidOperationException>(
() => new MemberMapper(new FieldMatcher()).MapPropertiesToMembers(entityType)).Message);
}
示例12: CreateModel
private static Model CreateModel(bool generateValues = true)
{
var model = new Model();
var entityType = model.AddEntityType("Led");
entityType.AddProperty("Zeppelin", typeof(Guid));
entityType.AddProperty("Stairway", typeof(Guid)).RequiresValueGenerator = generateValues;
return model;
}
示例13: Validates_properties_from_same_entity
public void Validates_properties_from_same_entity()
{
var entityType1 = new Model().AddEntityType(typeof(Customer));
var entityType2 = new Model().AddEntityType(typeof(Order));
var property1 = entityType1.GetOrAddProperty(Customer.IdProperty);
var property2 = entityType2.GetOrAddProperty(Order.NameProperty);
Assert.Equal(CoreStrings.KeyPropertiesWrongEntity($"{{'{property1.Name}', '{property2.Name}'}}", entityType1.DisplayName()),
Assert.Throws<InvalidOperationException>(
() => entityType1.AddKey(new[] { property1, property2 })).Message);
}
示例14: FieldMatchTest
private static void FieldMatchTest(string propertyName, string fieldName)
{
var entityType = new Model().AddEntityType(typeof(TheDarkSideOfTheMoon));
var property = entityType.AddProperty(propertyName, typeof(int), shadow: false);
var propertyInfo = entityType.ClrType.GetAnyProperty(propertyName);
var fields = propertyInfo.DeclaringType.GetRuntimeFields().ToDictionary(f => f.Name);
var matchedField = new FieldMatcher().TryMatchFieldName(property, propertyInfo, fields);
Assert.Equal(fieldName, matchedField.Name);
}
示例15: Default_nullability_of_property_is_based_on_nullability_of_CLR_type
public void Default_nullability_of_property_is_based_on_nullability_of_CLR_type()
{
var entityType = new Model().AddEntityType(typeof(object));
var stringProperty = entityType.AddProperty("stringName", typeof(string));
var nullableIntProperty = entityType.AddProperty("nullableIntName", typeof(int?));
var intProperty = entityType.AddProperty("intName", typeof(int));
Assert.True(stringProperty.IsNullable);
Assert.True(nullableIntProperty.IsNullable);
Assert.False(intProperty.IsNullable);
}