ORM及代码生成器和插件C#源码(最新版Kenly.DBFramework4.5.8.5)
对象关系映射架构(DBFramework)及代码生成器源码 http://lknoodle.download.csdn.net/
一、使用对象关系映射组件Kenly.DBFramework.dll不用编写任何SQL或者存储过程即可实现下列功能:
1、数据表、视图和存储过程与对象之间的转换。
2、数据表、视图的自定义条件查询。
3、数据表、视图的分页查询。
4、根据ID、主键或自定义条件对数据表进行增、删、改操作。
5、实现一对一、一对多、多对一和多对多的关系映射。
6、支持单个对象和多个对象之间的事务控制。
7、支持查询结果排序。
8、支持查询表达式生成。
9、支持延迟加载。
二、代码生成器
1、根据指定的数据库连接,自动生成数据表、视图和存储过程对应的对象代码(C#代码)。
2、自动生成相关的工程文件,生成完整的业务层项目文件。
3、可以帮助生成自定义查询方法。
4、支持SQLServer2000、SQLServer2005和Oracle代码生成插件,支持插件扩展。
提供
1、对象关系映射组件: Kenly.DBFramework.dll
2、代码生成器源码:CodeHelper。
3、代码生成器插件源码(支持SQLServer2000、SQLServer2005和Oracle):Plugin。
4、使用手册:DBFramework.Manual V4.5.3.pdf。
主要API:
public abstract class ViewGateway<T> where T: new()
{
// Methods
static ViewGateway();
protected ViewGateway();
protected static int Count();
protected static int Count(string condition);
protected static List<int> CountGroup(string groupBy);
protected static List<int> CountGroup(string condition, string groupBy);
public static List<T> CreateInstances(int count);
protected static List<ColumnType> Distinct<ColumnType>(string columnName);
protected static List<ColumnType> Distinct<ColumnType>(string columnName, string condition);
protected static List<ColumnType> Distinct<ColumnType>(string columnName, string condition, bool ignoreNull);
protected static bool Exists(string condition);
public bool ExistsById();
public bool ExistsByPK();
protected static List<T> Find(PagingArg pagingArg, params string[] propertyNames);
protected static List<T> Find(string condition, params string[] propertyNames);
protected static List<T> Find(PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames);
protected static List<T> Find(string condition, PagingArg pagingArg, params string[] propertyNames);
protected static List<T> Find(string condition, PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames);
protected static List<T> FindAll(params string[] propertyNames);
protected static void FindTop(T firstOne);
protected static List<T> FindTop(int topCount, params string[] propertyNames);
protected static void FindTop(string condition, T firstOne);
protected static List<T> FindTop(string condition, int topCount, params string[] propertyNames);
protected static void InitializeGateway(GatewayConfig config);
protected static void InitializeGateway(DatabaseType dbType, string connectionString);
protected void InitializeInstance(T entity);
protected static object Max(string columnName);
protected static object Max(string columnName, string condition);
protected static List<object> MaxGroup(string columnName, string groupBy);
protected static List<object> MaxGroup(string columnName, string condition, string groupBy);
protected static object Min(string columnName);
protected static object Min(string columnName, string condition);
protected static List<object> MinGroup(string columnName, string groupBy);
protected static List<object> MinGroup(string columnName, string condition, string groupBy);
protected static DataTable Query(PagingArg pagingArg, params string[] propertyNames);
protected static DataTable Query(string condition, params string[] propertyNames);
protected static DataTable Query(PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames);
protected static DataTable Query(string condition, PagingArg pagingArg, params string[] propertyNames);
protected static DataTable Query(string condition, PagingArg pagingArg, bool sqlServer2000, params string[] propertyNames);
protected static DataTable QueryAll(params string[] propertyNames);
protected static DataTable QueryTop(int topCount, params string[] propertyNames);
protected static DataTable QueryTop(string condition, int topCount, params string[] propertyNames);
public ArrayList RetrieveAssociations();
public ArrayList RetrieveAssociations(Type elementType);
public ArrayList RetrieveAssociations(params Type[] elementTypes);
public void RetrieveById();
public void RetrieveByPK();
protected internal virtual void RetrieveBySql(string sql);
public void ShadowCopyTo(object targetEntity);
public void ShadowCopyTo(T targetEntity);
protected static double Sum(string columnName);
protected static double Sum(string columnName, string condition);
protected static List<double> SumGroup(string columnName, string groupBy);
protected static List<double> SumGroup(string columnName, string condition, string groupBy);
public static string ToColumnName(string propertyName);
public static T ToObject(DataRow adaptedRow);
public static List<T> ToObjects(DataTable adaptedTable);
public static List<T> ToObjects(DataRow[] adaptedRows);
public static string ToPropertyName(string columnName);
public static DataTable ToTable(IList<T> entities);
public static DataTable ToTable(params T[] entities);
public static DataTable ToTable(bool isAdapted, params T[] entities);
public static DataTable ToTable(bool isAdapted, IList<T> entities);
// Properties
protected internal static string CommandText { get; }
protected internal static GatewayConfig Config { get; }
internal T Entity { get; set; }
public object EntityId { get; }
public object PrimaryKey { get; }
protected static Order SortedOrder { get; set; }
}
public abstract class TableGateway<T> : ViewGateway<T> where T: TableGateway<T>, new()
{
// Methods
static TableGateway();
protected TableGateway();
public int AddNew();
public static int AddNew(IList<T> entities);
public static int AddNew(T entity);
public int AddNew(bool returnIdentity);
public static int AddNew(T entity, bool returnIdentity);
public static int AddNew(IList<T> entities, out Transaction transaction);
public static int AddNew(IList<T> entities, bool returnIdentity);
public static int AddNew(T entity, out Transaction transaction);
public static int AddNew(IList<T> entities, bool returnIdentity, out Transaction transaction);
public static int AddNew(T entity, bool returnIdentity, out Transaction transaction);
public IDbTransaction BeginTransaction();
public IDbTransaction BeginTransaction(IsolationLevel isolationLevel);
public IDbTransaction BeginTransaction(double activeTime);
public IDbTransaction BeginTransaction(IsolationLevel isolationLevel, double activeTime);
public bool Commit();
protected static int Delete(string condition);
protected static int Delete(string condition, out Transaction transaction);
public int DeleteById();
public static int DeleteById(T entity);
public static int DeleteById(IList<T> entities);
public static int DeleteById(IList<T> entities, out Transaction transaction);
public static int DeleteById(T entity, out Transaction transaction);
public int DeleteByPK();
public static int DeleteByPK(T entity);
public static int DeleteByPK(IList<T> entities);
public static int DeleteByPK(IList<T> entities, out Transaction transaction);
public static int DeleteByPK(T entity, out Transaction transaction);
protected void OnPropertyChanged(MethodBase propertyMethod);
protected void OnPropertyChanged(string propertyName);
protected internal override void RetrieveBySql(string sql);
public bool Rollback();
protected static int Update(T entity, string condition);
protected static int Update(T entity, string condition, out Transaction transaction);
public int UpdateById();
public static int UpdateById(IList<T> entities);
public static int UpdateById(T entity);
public static int UpdateById(T entity, out Transaction transaction);
public static int UpdateById(IList<T> entities, out Transaction transaction);
public int UpdateByPK();
public static int UpdateByPK(IList<T> entities);
public static int UpdateByPK(T entity);
public static int UpdateByPK(IList<T> entities, out Transaction transaction);
public static int UpdateByPK(T entity, out Transaction transaction);
// Properties
public bool Changed { get; }
public List<string> ChangedPropertyNames { get; }
}
public class StoredProcedure<T> : IStoredProcedure
{
public bool BeginTransaction();
public void CloseReader(IDataReader reader);
public bool Commit();
public DataSet ExecuteDataSet();
public DataTable ExecuteDataTable();
public DataTable ExecuteDataTable<Ttarget>();
public List<Ttarget> ExecuteEntity<Ttarget>();
public int ExecuteNonQuery();
public IDataReader ExecuteReader();
public object ExecuteScalar();
protected static void InitializeGateway(GatewayConfig config);
protected static void InitializeGateway(DatabaseType dbType, string connectionString);
protected void InitializeInstance(T entity);
public bool Rollback();
}
public class AggregateEntity<T> where T: AggregateEntity<T>, new()
{
public static List<T> Execute();
protected static List<T> Execute(string condition);
public static DataTable ExecuteDataTable();
protected static DataTable ExecuteDataTable(string condition);
protected static void InitializeGateway(GatewayConfig config);
protected static void InitializeGateway(DatabaseType dbType, string connectionString);
// Properties
protected static Order SortedOrder { get; set; }
}
public static class EntityMapper<T>
{
// Methods
public static void AdaptToDatabase(DataTable adaptedTable);
public static void AdaptToEntity(DataTable rawTable);
public static void CopyToEntities(IList<T> entities, IList<DataRow> adaptedRows);
public static void CopyToEntities(IList<T> entities, DataTable adaptedTable);
public static void CopyToEntity(T entity, DataRow row);
public static List<T> CreateEntities(int count);
public static DataTable CreateTable();
public static DataTable CreateTable(bool isAdapted);
public static string ToColumnName(string propertyName);
public static List<T> ToEntities(IList<DataRow> adaptedRows);
public static List<T> ToEntities(DataTable table);
public static T ToEntity(DataRow adaptedRow);
public static string ToPropertyName(string columnName);
public static DataTable ToTable(IList<T> entities);
public static DataTable ToTable(params T[] entities);
public static DataTable ToTable(bool isAdapted, params T[] entities);
public static DataTable ToTable(bool isAdapted, IList<T> entities);
}
public static class EntityUtility
{
// Methods
public static List<T> Inherit<T>(IList entities);
public static T Inherit<T>(object entity);
public static T Inherit<Tbase, T>(Tbase baseEntity, TransformAction<Tbase, T> method);
public static List<T> Inherit<Tbase, T>(IList<Tbase> baseEntities, TransformAction<Tbase, T> method);
public static void ShadowCopy(IList targetEntities, IList sourceEntities);
public static void ShadowCopy(object targetEntity, object sourceEntity);
}