Hxj.Data Êý¾Ý¿â×é¼þÎĵµ ÏÂÔØ±¾ÎÄ

{

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();

//¿ªÆôÐÞ¸Ä (Ð޸IJÙ×÷֮ǰ ±ØÐëÖ´Ðд˷½·¨) 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