Perst常用命令

时间:2023-12-15 22:06:56

Perst我使用的版本是4, 几乎支持所有的.net环境, 而且效率很高,比较稳定。

Perst常用命令

使用方法:

1:引用相应dll

2: 创建数据结构

public class Cp_struct : Persistent, System.ComponentModel.INotifyPropertyChanged

{

[FullTextIndexable]  // 创建索引

public string Cpph;

public string cpph { get { return this.Cpph; } set { if (this.Cpph != value) { this.Cpph = value; OnPropertyChanged("cpph"); } } }

public string cpmz { get { return this.Cpmz; } set { if (this.Cpmz != value) { this.Cpmz = value; OnPropertyChanged("cpmz"); } } }         public string Cpmz;

public string ddjs { get { return this.Ddjs; } set { if (this.Ddjs != value) { this.Ddjs = value; OnPropertyChanged("ddjs"); } } } public string Ddjs;

public decimal dj { get { return this.Dj; } set { if (this.Dj != value) { this.Dj = value; OnPropertyChanged("dj"); } } } public decimal Dj;

public decimal hydj { get { return this.Hydj; } set { if (this.Hydj != value) { this.Hydj = value; OnPropertyChanged("hydj"); } } } public decimal Hydj;

public string lastdate { get { return this.Lastdate; } set { if (this.Lastdate != value) { this.Lastdate = value; OnPropertyChanged("lastdate"); } } } public string Lastdate;

#region INotifyPropertyChanged Members

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(string propertyName)

{

System.ComponentModel.PropertyChangedEventHandler handler = this.PropertyChanged;

if (handler != null)

{

handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));

}

#endregion

public override void OnLoad()

{

base.OnLoad();

}

public override void Deallocate()

{

base.Deallocate();

}

}

3: 创建数据库

public static Database db;

应用程序开启时打开数据库

Storage instanse = StorageFactory.Instance.CreateStorage();             //初始化数据库文件为1M

instanse.SetProperty("perst.file.extension.quantum", 512 * 1024);             //数据库大小不够时,每次增加512K

instanse.SetProperty("perst.extension.quantum", 512 * 1024);

instanse.Open("demo.dbf");

db = new Database(instanse);

应用程序关闭时关闭数据库连接

db.Storage.Close();

4 常用的方法有:

//检索:

List<PrintData_H> pp = App.db.Select<PrintData_H>(p => (p.bigAccountDataId == y.bigAccountDataId)).ToList();
List<City> list = App.db.Select<City>("order by CityNum").ToList();

// 新增
 App.db.AddRecord(x);
 App.db.Storage.Commit();

// 修改
x.Store();
 App.db.UpdateFullTextIndex(x);

// 删除
 App.db.DeleteRecord(x);
 App.db.Storage.Commit();