// <summary> // Constructs a wrapper for the given entity. // Note: use EntityWrapperFactory instead of calling this constructor directly. // </summary> // <param name="entity"> The entity to wrap </param> // <param name="propertyStrategy"> A delegate to create the property accesor strategy object </param> // <param name="changeTrackingStrategy"> A delegate to create the change tracking strategy object </param> // <param name="keyStrategy"> A delegate to create the entity key strategy object </param> internal EntityWrapperWithoutRelationships( TEntity entity, Func <object, IPropertyAccessorStrategy> propertyStrategy, Func <object, IChangeTrackingStrategy> changeTrackingStrategy, Func <object, IEntityKeyStrategy> keyStrategy, bool overridesEquals) : base(entity, RelationshipManager.Create(), propertyStrategy, changeTrackingStrategy, keyStrategy, overridesEquals) { }
public static EntityCollection <TElement> CreateCollection <T, TElement>(this T entity, Expression <Func <T, EntityCollection <TElement> > > expr, params TElement[] items) where T : EntityObject where TElement : EntityObject { if (expr.Body.NodeType != ExpressionType.MemberAccess) { throw new ArgumentException("Expression is not correct.", "expr"); } var member = ((MemberExpression)expr.Body).Member; PropertyInfo pi = member as PropertyInfo; if (pi == null) { throw new ArgumentException("Expression is not correct.", "expr"); } EdmRelationshipNavigationPropertyAttribute attribute = (EdmRelationshipNavigationPropertyAttribute)Attribute.GetCustomAttribute(pi, typeof(EdmRelationshipNavigationPropertyAttribute)); EntityCollection <TElement> result = new EntityCollection <TElement>(); RelationshipManager rm = RelationshipManager.Create(entity); rm.InitializeRelatedCollection(attribute.RelationshipName, attribute.TargetRoleName, result); foreach (var item in items) { result.Add(item); } return(result); }
// <summary> // Constructs a wrapper as part of the materialization process. This constructor is only used // during materialization where it is known that the entity being wrapped is newly constructed. // This means that some checks are not performed that might be needed when thw wrapper is // created at other times, and information such as the identity type is passed in because // it is readily available in the materializer. // </summary> // <param name="entity"> The entity to wrap </param> // <param name="key"> The entity's key </param> // <param name="entitySet"> The entity set, or null if none is known </param> // <param name="context"> The context to which the entity should be attached </param> // <param name="mergeOption"> NoTracking for non-tracked entities, AppendOnly otherwise </param> // <param name="identityType"> The type of the entity ignoring any possible proxy type </param> // <param name="propertyStrategy"> A delegate to create the property accesor strategy object </param> // <param name="changeTrackingStrategy"> A delegate to create the change tracking strategy object </param> // <param name="keyStrategy"> A delegate to create the entity key strategy object </param> internal EntityWrapperWithoutRelationships( TEntity entity, EntityKey key, EntitySet entitySet, ObjectContext context, MergeOption mergeOption, Type identityType, Func <object, IPropertyAccessorStrategy> propertyStrategy, Func <object, IChangeTrackingStrategy> changeTrackingStrategy, Func <object, IEntityKeyStrategy> keyStrategy, bool overridesEquals) : base(entity, RelationshipManager.Create(), key, entitySet, context, mergeOption, identityType, propertyStrategy, changeTrackingStrategy, keyStrategy, overridesEquals) { }
public void Factory_sets_override_flag_appropriately_for_entities_with_relationships() { var mockWithRelationships = new Mock <IEntityWithRelationships>(); mockWithRelationships.Setup(m => m.RelationshipManager).Returns(RelationshipManager.Create(mockWithRelationships.Object)); var wrappedEntity = EntityWrapperFactory.CreateNewWrapper(mockWithRelationships.Object, new EntityKey()); Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition()); Assert.False(wrappedEntity.OverridesEqualsOrGetHashCode); wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new Mock <EntityWithRelationshipsAndEquals>().Object, new EntityKey()); Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition()); Assert.True(wrappedEntity.OverridesEqualsOrGetHashCode); }
public EntityWithRelationshipsButWithoutEquals() { RelationshipManager = RelationshipManager.Create(this); }
/// <summary> /// Creates a new <see cref="RelationshipManager"/> for the specified instance. /// </summary> /// <param name="instance"></param> /// <param name="property"></param> /// <returns></returns> public static RelationshipManager InitializeRelationshipManager(IEntityType instance, string property) { return(RelationshipManager.Create(instance)); }
public EntityWithRelationshipsAndEquals() { _relationshipManager = RelationshipManager.Create(this); }
public IPocoEntityWithEquals() { _relationshipManager = RelationshipManager.Create(this); }
public IPocoEntity() { _relationshipManager = RelationshipManager.Create(this); }