第一范文网 - 专业文章范例文档资料分享平台

Hxj.Data 数据库组件文档

来源:用户分享 时间:2025/5/16 4:25:21 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{

return new Field[] { _.ProductID}; }

///

/// 获取列信息 ///

public override Field[] GetFields() {

return new Field[] { _.ProductID, _.ProductName, _.SupplierID, _.CategoryID, _.QuantityPerUnit, _.UnitPrice, _.UnitsInStock, _.UnitsOnOrder, _.ReorderLevel, _.Discontinued}; }

///

/// 获取值信息 ///

public override object[] GetValues() {

return new object[] { this._ProductID, this._ProductName, this._SupplierID, this._CategoryID, this._QuantityPerUnit, this._UnitPrice, this._UnitsInStock, this._UnitsOnOrder, this._ReorderLevel, this._Discontinued}; }

///

/// 给当前实体赋值 ///

public override void SetPropertyValues(IDataReader reader) {

this._ProductID = DataUtils.ConvertValue(reader[\]);

9

this._ProductName = DataUtils.ConvertValue(reader[\]); this._SupplierID = DataUtils.ConvertValue(reader[\]); this._CategoryID = DataUtils.ConvertValue(reader[\]); this._QuantityPerUnit =

DataUtils.ConvertValue(reader[\]);

this._UnitPrice = DataUtils.ConvertValue(reader[\]); this._UnitsInStock = DataUtils.ConvertValue(reader[\]); this._UnitsOnOrder = DataUtils.ConvertValue(reader[\]); this._ReorderLevel = DataUtils.ConvertValue(reader[\]); this._Discontinued = DataUtils.ConvertValue(reader[\]); }

///

/// 给当前实体赋值 ///

public override void SetPropertyValues(DataRow row) {

this._ProductID = DataUtils.ConvertValue(row[\]);

this._ProductName = DataUtils.ConvertValue(row[\]); this._SupplierID = DataUtils.ConvertValue(row[\]); this._CategoryID = DataUtils.ConvertValue(row[\]); this._QuantityPerUnit =

DataUtils.ConvertValue(row[\]);

this._UnitPrice = DataUtils.ConvertValue(row[\]); this._UnitsInStock = DataUtils.ConvertValue(row[\]); this._UnitsOnOrder = DataUtils.ConvertValue(row[\]); this._ReorderLevel = DataUtils.ConvertValue(row[\]); this._Discontinued = DataUtils.ConvertValue(row[\]); }

#endregion

#region _Field ///

/// 字段信息 /// public class _ {

public readonly static Field All = new Field(\,\); public readonly static Field ProductID = new Field(\,\,\);

public readonly static Field ProductName = new Field(\,\,\);

public readonly static Field SupplierID = new Field(\,\,\);

public readonly static Field CategoryID = new

10

Field(\,\,\);

public readonly static Field QuantityPerUnit = new Field(\,\,\); public readonly static Field UnitPrice = new Field(\,\,\);

public readonly static Field UnitsInStock = new Field(\,\,\);

public readonly static Field UnitsOnOrder = new Field(\,\,\);

public readonly static Field ReorderLevel = new Field(\,\,\);

public readonly static Field Discontinued = new Field(\,\,\); }

#endregion } }

数据组件默认入口为:Hxj.Data.DbSession.Default 会自动读取config文件中connectionStrings节点的最后一个连接配置。 当然可根据不同的数据连接实例化新的DbSession。 查询示例:

1、查询Products表所有数据的信息,返回实体列表。

List list = DbSession.Default.From().ToList();

2、查询其他的简单示例。

DbSession.Default.From()

//.Select(Products._.ProductID)

//.GroupBy(Products._.CategoryID.GroupBy && Products._.ProductName.GroupBy) // .InnerJoin(Suppliers._.SupplierID == Products._.SupplierID) // .Select(Products._.CategoryID, Products._.ProductName, Products._.ProductID)//, Suppliers._.CompanyName, Suppliers._.ContactName //.OrderBy(Products._.ProductID.Asc)

//.Where((Products._.ProductName.Contain(null) && Products._.UnitPrice > 1) || Products._.CategoryID == 2)

//.UnionAll(DbSession.Default.From().Select(Products._.ProductID)) .Page(10, 1)

11

//.ToList(); .ToDataSet();

添加示例:

例子是web下的。

//新建一个实体

Products p = new Products();

//开启修改 (开启修改后的添加操作将只insert赋值过的字段) p.Attach();

//获取页面中输入的值

EntityUtils.UpdateModel(p, Request.Form, \);

//返回值 如果有自增长字段,则返回自增长字段的值

int returnValue = DbSession.Default.Insert(p);

修改示例:

修改Products表第一条数据的ProductName的值。

//获取Products表第一行

Products p = DbSession.Default.From().ToFirst();

//开启修改 (修改操作之前 必须执行此方法) p.Attach();

p.ProductName = txtValue.Text.Trim(); //更新

//返回0表示更新失败 组件有事务会自动回滚 //返回1表示更新成功

//更新成功返回值就是受影响的条数

int returnvalue = DbSession.Default.Update(p);

删除示例:

参数为主键的值,也可传入实体。

//删除 条件 ProductID=2

//返回0表示删除失败 组件有事务会自动回滚 //返回1表示删除成功

//删除成功返回值就是受影响的条数

int returnvalue = DbSession.Default.Delete(2);

组件还支持事务,批处理等功能。

12

搜索更多关于: Hxj.Data 数据库组件文档 的文档
Hxj.Data 数据库组件文档.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c13kcf3awwh2nsft0jg4x_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top