本文整理汇总了C#中AdvancedPatternsModel.AdvancedPatternsMasterContext类的典型用法代码示例。如果您正苦于以下问题:C# AdvancedPatternsMasterContext类的具体用法?C# AdvancedPatternsMasterContext怎么用?C# AdvancedPatternsMasterContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AdvancedPatternsMasterContext类属于AdvancedPatternsModel命名空间,在下文中一共展示了AdvancedPatternsMasterContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DbPropertyValues_ToObject_for_an_entity_works_under_partial_trust
public void DbPropertyValues_ToObject_for_an_entity_works_under_partial_trust()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var buildingClone = (Building)context.Entry(building).CurrentValues.ToObject();
Assert.Equal("Building One", buildingClone.Name);
}
}
示例2: DbPropertyValues_ToObject_for_a_complex_type_works_under_partial_trust
public void DbPropertyValues_ToObject_for_a_complex_type_works_under_partial_trust()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var addressClone =
(Address)context.Entry(building).CurrentValues.GetValue<DbPropertyValues>("Address").ToObject();
Assert.Equal("Redmond", addressClone.City);
}
}
示例3: AnonymousType_join_selecting_one_member
private void AnonymousType_join_selecting_one_member()
{
using (var context = new AdvancedPatternsMasterContext())
{
var query = context.WorkOrders.Select(wo => wo.EmployeeId)
.Join(
context.Employees.Select(e => e.EmployeeId), a => a, b => b, (a, b) => new
{
a
});
var sql = query.ToString();
Assert.True(sql != null);
}
}
示例4: GroupBy_aggregate_pushdown_single_key
private void GroupBy_aggregate_pushdown_single_key()
{
using (var context = new AdvancedPatternsMasterContext())
{
var groupByQuery = from workOrder in context.WorkOrders
group new
{
workOrder.WorkOrderId,
workOrder.Details
} by workOrder.EmployeeId
into ordersByEmployeeGroup
select new
{
EmployeeId = ordersByEmployeeGroup.Key,
OrderCount = ordersByEmployeeGroup.Count(),
MaxOrderId = ordersByEmployeeGroup.Max(o => o.WorkOrderId)
};
var sql = groupByQuery.ToString();
Assert.True(sql != null && sql.ToUpper().Contains("GROUP BY"));
}
}
示例5: Can_create_non_generic_DbSet_for_abstract_base_type
public void Can_create_non_generic_DbSet_for_abstract_base_type()
{
using (var context = new AdvancedPatternsMasterContext())
{
var set = context.Set(typeof(Employee));
Assert.Equal(typeof(Employee), set.ElementType);
var entity = set.Cast<Employee>().FirstOrDefault();
Assert.IsAssignableFrom<Employee>(entity);
}
}
示例6: Setting_IsModified_to_false_for_a_modified_complex_property_rejects_changes_to_that_property
public void Setting_IsModified_to_false_for_a_modified_complex_property_rejects_changes_to_that_property()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
entry.ComplexProperty(b => b.Address).CurrentValue = CreateNewAddress();
Assert.True(entry.Property(b => b.Address).IsModified);
entry.ComplexProperty(b => b.Address).IsModified = false;
ValidateBuildingAndNameNotModified(context, building);
}
}
示例7: IsModified_can_be_set_to_false_when_it_is_currently_false
public void IsModified_can_be_set_to_false_when_it_is_currently_false()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
entry.Property(b => b.Name).IsModified = false;
entry.ComplexProperty(b => b.Address).IsModified = false;
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified
= false;
Assert.False(entry.Property(b => b.Name).IsModified);
Assert.False(entry.ComplexProperty(b => b.Address).IsModified);
Assert.False(
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).
IsModified);
Assert.Equal(EntityState.Unchanged, entry.State);
var objectContext = GetObjectContext(context);
Assert.Equal(0,
objectContext.ObjectStateManager.GetObjectStateEntry(building).GetModifiedProperties().
Count());
}
}
示例8: IsModified_can_be_set_to_true_when_it_is_currently_true
public void IsModified_can_be_set_to_true_when_it_is_currently_true()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
entry.Property(b => b.Name).IsModified = true;
entry.ComplexProperty(b => b.Address).IsModified = true;
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified
= true;
entry.Property(b => b.Name).IsModified = true;
entry.ComplexProperty(b => b.Address).IsModified = true;
entry.ComplexProperty(b => b.Address).ComplexProperty(a => a.SiteInfo).Property(i => i.Zone).IsModified
= true;
ValidateModifiedProperties(context, building);
}
}
示例9: TestPropertyValuePositiveForState
private void TestPropertyValuePositiveForState(Func<DbPropertyEntry<Building, string>, string> getValue,
Action<DbPropertyEntry<Building, string>, string> setValue,
EntityState state)
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var propEntry = entry.Property(b => b.Name);
entry.State = state;
Assert.Equal("Building One", getValue(propEntry));
setValue(propEntry, "New Building");
Assert.Equal("New Building", getValue(propEntry));
}
}
示例10: Using_wrong_generic_type_with_nested_complex_string_Property_method_throws
public void Using_wrong_generic_type_with_nested_complex_string_Property_method_throws()
{
using (var context = new AdvancedPatternsMasterContext())
{
var propertyEntry = GetBuildingEntry(context).ComplexProperty(b => b.Address);
Assert.Throws<ArgumentException>(() => propertyEntry.Property<Building>("SiteInfo")).ValidateMessage(
"DbEntityEntry_WrongGenericForProp", "SiteInfo", "Address", "Building", "SiteInfo");
}
}
示例11: IsPropertyChanged_returns_true_for_scalar_property_that_is_changed_and_marked_as_modified
public void IsPropertyChanged_returns_true_for_scalar_property_that_is_changed_and_marked_as_modified()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(building);
entry.Property(b => b.Name).CurrentValue = "Oops I Did It Again!";
Assert.True(entry.Property(b => b.Name).IsModified);
Assert.True(stateEntry.IsPropertyChanged("Name"));
building.Name = "Building Two";
context.ChangeTracker.DetectChanges();
building.Name = "Building One";
context.ChangeTracker.DetectChanges();
Assert.True(entry.Property(b => b.Name).IsModified);
Assert.False(stateEntry.IsPropertyChanged("Name"));
}
}
示例12: IsPropertyChangedTest
private void IsPropertyChangedTest(Action<Building, DbEntityEntry<Building>, ObjectStateEntry> test)
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var entry = context.Entry(building);
var stateEntry = GetObjectContext(context).ObjectStateManager.GetObjectStateEntry(building);
test(building, entry, stateEntry);
}
}
示例13: using
public void IsModified_stays_true_for_properties_of_a_complex_property_until_changes_are_rejected_to_all_properties_even_if_the_instance_has_been_changed()
{
using (var context = new AdvancedPatternsMasterContext())
{
var building = context.Buildings.Single(b => b.Name == "Building One");
var addressEntry = context.Entry(building).ComplexProperty(b => b.Address);
var originalAddress = building.Address;
var newAddress = CloneAddress(originalAddress);
newAddress.SiteInfo = originalAddress.SiteInfo; // Keep same nested complex instance
building.Address = newAddress;
building.Address.City = "Grimsby";
addressEntry = context.Entry(building).ComplexProperty(b => b.Address);
AssertStateOfAddressProperties(addressEntry, "Grimsby", "WA", "Clean", isModified: true);
addressEntry.Property(a => a.City).IsModified = false;
AssertStateOfAddressProperties(addressEntry, "Redmond", "WA", "Clean", isModified: false);
}
}
示例14: Using_base_collection_type_for_navigation_property_derived_from_ICollection_entry_using_Member_throws
Using_base_collection_type_for_navigation_property_derived_from_ICollection_entry_using_Member_throws()
{
using (var context = new AdvancedPatternsMasterContext())
{
var entityEntry = GetBuildingEntry(context);
// MailRooms is typed as IList<MailRoom> so this should never work
Assert.Throws<ArgumentException>(() => entityEntry.Member<List<MailRoom>>("MailRooms")).ValidateMessage(
"DbEntityEntry_WrongGenericForCollectionNavProp", typeof(List<MailRoom>).ToString(), "MailRooms",
typeof(Building).ToString(), typeof(ICollection<MailRoom>).ToString());
}
}
示例15: Using_wrong_generic_type_for_complex_property_with_string_Member_method_throws
public void Using_wrong_generic_type_for_complex_property_with_string_Member_method_throws()
{
using (var context = new AdvancedPatternsMasterContext())
{
var entry = GetBuildingEntry(context);
Assert.Throws<ArgumentException>(() => entry.Member<string>("Address")).ValidateMessage(
"DbEntityEntry_WrongGenericForProp", "Address", "Building", "String", "Address");
}
}