/// <summary> /// Creates a proxy instance for an entity type if proxy creation has been turned on. /// </summary> /// <typeparam name="TEntity"> The entity type for which a proxy is needed. </typeparam> /// <param name="context"> The <see cref="DbContext" />. </param> /// <param name="configureEntity"> Called after the entity is created to set property values, etc. </param> /// <param name="constructorArguments"> Arguments to pass to the entity type constructor. </param> /// <returns> The proxy instance. </returns> public static TEntity CreateProxy <TEntity>( [NotNull] this DbContext context, [CanBeNull] Action <TEntity> configureEntity, [NotNull] params object[] constructorArguments) { var entity = (TEntity)context.CreateProxy(typeof(TEntity), constructorArguments); configureEntity?.Invoke(entity); return(entity); }
/// <summary> /// Creates a proxy instance for an entity type if proxy creation has been turned on. /// </summary> /// <typeparam name="TEntity"> The entity type for which a proxy is needed. </typeparam> /// <param name="context"> The <see cref="DbContext" />. </param> /// <param name="constructorArguments"> Arguments to pass to the entity type constructor. </param> /// <returns> The proxy instance. </returns> public static TEntity CreateProxy <TEntity>( [NotNull] this DbContext context, [NotNull] params object[] constructorArguments) => (TEntity)context.CreateProxy(typeof(TEntity), constructorArguments);