public static TEntity CreateProxy <TEntity>( this DbSet <TEntity> set, params object[] constructorArguments) where TEntity : class { return((TEntity)set.GetInfrastructure().CreateProxy(typeof(TEntity), constructorArguments)); }
/// <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="set"> The <see cref="DbSet{TEntity}" />. </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 DbSet <TEntity> set, [NotNull] params object[] constructorArguments) where TEntity : class { Check.NotNull(set, nameof(set)); Check.NotNull(constructorArguments, nameof(constructorArguments)); return((TEntity)set.GetInfrastructure().CreateProxy(typeof(TEntity), constructorArguments)); }
/// <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="set"> The <see cref="DbSet{TEntity}" />. </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 DbSet <TEntity> set, [CanBeNull] Action <TEntity> configureEntity, [NotNull] params object[] constructorArguments) where TEntity : class { Check.NotNull(set, nameof(set)); Check.NotNull(constructorArguments, nameof(constructorArguments)); var entity = (TEntity)set.GetInfrastructure().CreateProxy(typeof(TEntity), constructorArguments); configureEntity?.Invoke(entity); return(entity); }
public static DbContext GetDbContext <TEntity>(this DbSet <TEntity> set) where TEntity : class => set.GetInfrastructure().GetService <IDbContextServices>().CurrentContext.Context;