private int ExecuteQuery <T>(T data, Func <EntityQuery, EntityBase, int> fun, EntityQueryExecuteType executeType) where T : class { EntityBase entity = data as EntityBase; if (entity == null) //T 是接口类型,data 是一个实现了该接口的DTO { T temp = EntityBuilder.CreateEntity <T>(); entity = temp as EntityBase; entity.MapFrom(data, true);//使用该重载方法,可以不用调用下面一行代码 //entity.ResetChanges(true); } EntityQueryExecuteEventArgs args = new EntityQueryExecuteEventArgs(entity, executeType); if (this.OnBeforeExecute != null) { this.OnBeforeExecute(this, args); } EntityQuery eq = new EntityQuery(CurrentDataBase); int accept = fun(eq, entity); args.Success = accept > 0; if (this.OnAfterExecute != null) { this.OnAfterExecute(this, args); } return(accept); }
/// <summary> /// 使用实体类和查询类型初始化本类 /// </summary> /// <param name="entity"></param> /// <param name="executeType"></param> public EntityQueryExecuteEventArgs(EntityBase entity, EntityQueryExecuteType executeType) { this.Entity = entity; this.ExecuteType = executeType; }