浏览 1602 次
锁定老帖子 主题:活动记录框架
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-06-22
先介绍简单的CRUD操作。 建立表结构: Csharp代码 create table products( id int primary key identity, name varchar(50), shape varchar(50), amount int, remark varchar(200) ) create table products( id int primary key identity, name varchar(50), shape varchar(50), amount int, remark varchar(200) ) 然后定义类: Csharp代码 using EtNet.ActiveRecord; [Table("products")] public class Product : ActiveRecordBase { public Product() { // // TODO: 在此处添加构造函数逻辑 // } [PrimaryKey] public int id { get {return _id;} set {_id = value;} } [Field] public string name { get {return _name;} set {_name = value;} } [Field] public string shape { get {return _shape;} set {_shape = value;} } [Field] public int amount { get {return _amount;} set {_amount = value;} } [Field] public string remark { get {return _remark;} set {_remark = value;} } private int _id; private string _name; private string _shape; private int _amount; private string _remark; } using EtNet.ActiveRecord; [Table("products")] public class Product : ActiveRecordBase { public Product() { // // TODO: 在此处添加构造函数逻辑 // } [PrimaryKey] public int id { get {return _id;} set {_id = value;} } [Field] public string name { get {return _name;} set {_name = value;} } [Field] public string shape { get {return _shape;} set {_shape = value;} } [Field] public int amount { get {return _amount;} set {_amount = value;} } [Field] public string remark { get {return _remark;} set {_remark = value;} } private int _id; private string _name; private string _shape; private int _amount; private string _remark; } 1、增加记录 Csharp代码 Product p = new Product(); p.name = "电脑"; p.shape = "PII"; p.amount = 30; p.Create(); Product p = new Product(); p.name = "电脑"; p.shape = "PII"; p.amount = 30; p.Create(); 2、修改记录 Csharp代码 Product p = (Product)Product.Find(typeof(Product),1); p.shape = "PIII"; p.amount = 23; p.remark = "备用"; p.Update(); Product p = (Product)Product.Find(typeof(Product),1); p.shape = "PIII"; p.amount = 23; p.remark = "备用"; p.Update(); 3、删除记录 Csharp代码 Product p = (Product)Product.Find(typeof(Product),1); p.Destroy(); Product p = (Product)Product.Find(typeof(Product),1); p.Destroy(); 4、查询记录 Csharp代码 Product p = (Product)Product.Find(typeof(Product),1); Console.WriteLine(p.id); Console.WriteLine(p.name); Console.WriteLine(p.shape); Console.WriteLine(p.amount); Product p = (Product)Product.Find(typeof(Product),1); Console.WriteLine(p.id); Console.WriteLine(p.name); Console.WriteLine(p.shape); Console.WriteLine(p.amount); 其他的功能操作以后再介绍。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-09-19
备用,希望你尽快更新
|
|
返回顶楼 | |