public void Delegate_setter_is_cached_by_type_and_property_name() { var entityType = new EntityType(typeof(Customer)); var idProperty = entityType.AddProperty("Id", typeof(int)); var source = new ClrPropertySetterSource(); var accessor = source.GetAccessor(typeof(Customer), "Id"); Assert.Same(accessor, source.GetAccessor(typeof(Customer), "Id")); Assert.Same(accessor, source.GetAccessor(idProperty)); }
public void Delegate_setter_is_cached_by_type_and_property_name() { var entityType = new Model().AddEntityType(typeof(Customer)); var idProperty = entityType.GetOrAddProperty("Id", typeof(int)); var source = new ClrPropertySetterSource(); var accessor = source.GetAccessor(typeof(Customer), "Id"); Assert.Same(accessor, source.GetAccessor(typeof(Customer), "Id")); Assert.Same(accessor, source.GetAccessor(idProperty)); }
private void DoFixup(IForeignKey foreignKey, StateEntry principalEntry, StateEntry[] dependentEntries) { foreach (var navigation in _stateManager.Model.GetNavigations(foreignKey)) { if (navigation.EntityType == principalEntry.EntityType) { var accessor = _collectionAccessorSource.GetAccessor(navigation); foreach (var dependent in dependentEntries) { if (!accessor.Contains(principalEntry.Entity, dependent.Entity)) { accessor.Add(principalEntry.Entity, dependent.Entity); } } } else { var accessor = _setterSource.GetAccessor(navigation); foreach (var dependent in dependentEntries) { accessor.SetClrValue(dependent.Entity, principalEntry.Entity); } } } }
public virtual void WriteValue([NotNull] object entity, [NotNull] IPropertyBase propertyBase, [CanBeNull] object value) { Check.NotNull(entity, "entity"); Check.NotNull(propertyBase, "propertyBase"); _setterSource.GetAccessor(propertyBase).SetClrValue(entity, value); }
public void Property_is_returned_if_it_implements_IClrPropertySetter() { var setterMock = new Mock<IClrPropertySetter>(); var propertyMock = setterMock.As<IProperty>(); var source = new ClrPropertySetterSource(); Assert.Same(setterMock.Object, source.GetAccessor(propertyMock.Object)); }
public void Property_is_returned_if_it_implements_IClrPropertySetter() { var setterMock = new Mock <IClrPropertySetter>(); var propertyMock = setterMock.As <IProperty>(); var source = new ClrPropertySetterSource(); Assert.Same(setterMock.Object, source.GetAccessor(propertyMock.Object)); }
public virtual void InitializeSets([NotNull] DbContext context) { Check.NotNull(context, "context"); foreach (var setInfo in _setFinder.FindSets(context).Where(p => p.HasSetter)) { _setSetters .GetAccessor(setInfo.ContextType, setInfo.Name) .SetClrValue(context, context.Set(setInfo.EntityType)); } }
private void DoFixup(IEnumerable <INavigation> navigations, StateEntry principalEntry, StateEntry[] dependentEntries) { foreach (var navigation in navigations) { if (navigation.PointsToPrincipal) { var setter = _setterSource.GetAccessor(navigation); foreach (var dependent in dependentEntries) { setter.SetClrValue(dependent.Entity, principalEntry.Entity); dependent.RelationshipsSnapshot.TakeSnapshot(navigation); } } else { if (navigation.IsCollection()) { var collectionAccessor = _collectionAccessorSource.GetAccessor(navigation); foreach (var dependent in dependentEntries) { if (!collectionAccessor.Contains(principalEntry.Entity, dependent.Entity)) { collectionAccessor.Add(principalEntry.Entity, dependent.Entity); } } } else { // TODO: Decide how to handle case where multiple values match non-collection nav prop // Issue #739 _setterSource.GetAccessor(navigation).SetClrValue(principalEntry.Entity, dependentEntries.Single().Entity); } principalEntry.RelationshipsSnapshot.TakeSnapshot(navigation); } } }
private void LoadNavigationProperties( object entity, INavigation navigation, IReadOnlyList <object> relatedEntities) { if (navigation.PointsToPrincipal) { _clrPropertySetterSource .GetAccessor(navigation) .SetClrValue(entity, relatedEntities[0]); var inverseNavigation = navigation.TryGetInverse(); if (inverseNavigation != null) { if (inverseNavigation.IsCollection()) { _clrCollectionAccessorSource .GetAccessor(inverseNavigation) .AddRange(relatedEntities[0], new[] { entity }); } else { _clrPropertySetterSource .GetAccessor(inverseNavigation) .SetClrValue(relatedEntities[0], entity); } } } else { if (navigation.IsCollection()) { _clrCollectionAccessorSource .GetAccessor(navigation) .AddRange(entity, relatedEntities); var inverseNavigation = navigation.TryGetInverse(); if (inverseNavigation != null) { var clrPropertySetter = _clrPropertySetterSource .GetAccessor(inverseNavigation); foreach (var relatedEntity in relatedEntities) { clrPropertySetter.SetClrValue(relatedEntity, entity); } } } else { _clrPropertySetterSource .GetAccessor(navigation) .SetClrValue(entity, relatedEntities[0]); var inverseNavigation = navigation.TryGetInverse(); if (inverseNavigation != null) { _clrPropertySetterSource .GetAccessor(inverseNavigation) .SetClrValue(relatedEntities[0], entity); } } } }