1- using System ;
2- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
32using System . Data ;
43using System . Data . Common ;
54using System . Data . Entity ;
65using System . Threading . Tasks ;
7- using SmartStore . Core ;
86
97namespace SmartStore . Core . Data
108{
@@ -83,36 +81,37 @@ IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params ob
8381 /// <typeparam name="TEntity">Type of entity</typeparam>
8482 /// <param name="entity">The entity instance to attach</param>
8583 /// <returns><c>true</c> when the entity is attched already, <c>false</c> otherwise</returns>
86- bool IsAttached < TEntity > ( TEntity entity ) where TEntity : BaseEntity , new ( ) ;
84+ bool IsAttached < TEntity > ( TEntity entity ) where TEntity : BaseEntity ;
8785
8886 /// <summary>
8987 /// Detaches an entity from the current object context if it's attached
9088 /// </summary>
9189 /// <typeparam name="TEntity">Type of entity</typeparam>
9290 /// <param name="entity">The entity instance to detach</param>
93- void DetachEntity < TEntity > ( TEntity entity ) where TEntity : BaseEntity , new ( ) ;
91+ void DetachEntity < TEntity > ( TEntity entity ) where TEntity : BaseEntity ;
9492
9593 /// <summary>
9694 /// Detaches all entities of type <c>TEntity</c> from the current object context
9795 /// </summary>
96+ /// <param name="unchangedEntitiesOnly">When <c>true</c>, only entities in unchanged state get detached.</param>
9897 /// <returns>The count of detached entities</returns>
99- int DetachEntities < TEntity > ( ) where TEntity : class ;
98+ int DetachEntities < TEntity > ( bool unchangedEntitiesOnly = true ) where TEntity : class ;
10099
101100 /// <summary>
102101 /// Change the state of an entity object
103102 /// </summary>
104103 /// <typeparam name="TEntity">Type of entity</typeparam>
105104 /// <param name="entity">The entity instance</param>
106105 /// <param name="newState">The new state</param>
107- void ChangeState < TEntity > ( TEntity entity , System . Data . Entity . EntityState newState ) where TEntity : BaseEntity , new ( ) ;
106+ void ChangeState < TEntity > ( TEntity entity , System . Data . Entity . EntityState newState ) where TEntity : BaseEntity ;
108107
109108 /// <summary>
110109 /// Reloads the entity from the database overwriting any property values with values from the database.
111110 /// The entity will be in the Unchanged state after calling this method.
112111 /// </summary>
113112 /// <typeparam name="TEntity">Type of entity</typeparam>
114113 /// <param name="entity">The entity instance</param>
115- void ReloadEntity < TEntity > ( TEntity entity ) where TEntity : BaseEntity , new ( ) ;
114+ void ReloadEntity < TEntity > ( TEntity entity ) where TEntity : BaseEntity ;
116115
117116 /// <summary>
118117 /// Begins a transaction on the underlying store connection using the specified isolation level
@@ -128,33 +127,4 @@ IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params ob
128127 void UseTransaction ( DbTransaction transaction ) ;
129128 }
130129
131- public static class IDbContextExtensions
132- {
133-
134- public static int DetachAll ( this IDbContext ctx )
135- {
136- return ctx . DetachEntities < BaseEntity > ( ) ;
137- }
138-
139- /// <summary>
140- /// Changes the object state to unchanged
141- /// </summary>
142- /// <typeparam name="TEntity">Type of entity</typeparam>
143- /// <param name="entity">The entity instance</param>
144- /// <returns>true on success, false on failure</returns>
145- public static bool SetToUnchanged < TEntity > ( this IDbContext ctx , TEntity entity ) where TEntity : BaseEntity , new ( )
146- {
147- try
148- {
149- ctx . ChangeState < TEntity > ( entity , System . Data . Entity . EntityState . Unchanged ) ;
150- return true ;
151- }
152- catch ( Exception ex )
153- {
154- ex . Dump ( ) ;
155- return false ;
156- }
157- }
158-
159- }
160130}
0 commit comments