博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sterling学习
阅读量:7076 次
发布时间:2019-06-28

本文共 4013 字,大约阅读时间需要 13 分钟。

1.启动和关闭引擎

private void _ActivateEngine()        {            _engine = new SterlingEngine();            _logger = new SterlingDefaultLogger(SterlingLogLevel.Verbose);            _engine.Activate();            Database = _engine.SterlingDatabase.RegisterDatabase
(new IsolatedStorageDriver()); } private void _DeactivateEngine() { Database.Flush(); _logger.Detach(); _engine.Dispose(); Database = null; _engine = null; }

2.加载/保存/删除:

public static void Save(this ListItem listItem)        {            int currentIndex = (Application.Current as App).Database.Query
().Count; if (listItem.Key == -1) { listItem.Key = currentIndex; } (Application.Current as App).Database.Save(listItem); (App.Current as App).Database.Flush(); } public static void Delete(this ListItem listItem) { // List
list = (Application.Current as App).Database.Query
(); //(App.Current as App).Database.Delete(typeof(ListItem), listItem.Text); (App.Current as App).Database.Truncate(typeof(ListItem)); (App.Current as App).Database.Flush(); } public static IEnumerable
Load(this IEnumerable
listItem) { var list = (Application.Current as App).Database.Query
(); return new ObservableCollection
(list.Select(item => item.LazyValue.Value).ToList()); } public static int Count(this ListItem listItem) { int currentIndex = (Application.Current as App).Database.Query
().Count; return currentIndex; }

3.删除指定的文本和指定的ID,以文本为例

public static void DeletebyText(string text)        {            var list = (Application.Current as App).Database.Query
(); ObservableCollection
collection = new ObservableCollection
( list.Select(item => item.LazyValue.Value).ToList().Where(item => item.Text.Equals(text)) ); foreach (var cll in collection) (App.Current as App).Database.Delete(cll); }

 

4.用于自动生成键的基础触发器

public class IdentityTrigger
: BaseSterlingTrigger
where T: class, IBaseModel, new(){ private static int _idx = 1; public IdentityTrigger(ISterlingDatabaseInstance database) { // If a record exists, set it to the highest value plus 1 if (database.Query
().Any()) { _idx = database.Query
().Max(key => key.Key) + 1; } } public override bool BeforeSave(T instance) { if (instance.Id < 1) { instance.Id = _idx++; } return true; } public override void AfterSave(T instance) { return; } public override bool BeforeDelete(int key) { return true; }}

5.自定义序列化程序

public class TypeSerializer : BaseSerializer {  ///   ///     Return true if this serializer can handle the object,   ///     that is, if it can be cast to type    ///   /// The target  /// 
True if it can be serialized
public override bool CanSerialize(Type targetType) { return typeof (Type).IsAssignableFrom(targetType); } /// /// Serialize the object /// /// The target /// The writer public override void Serialize(object target, BinaryWriter writer) { var type = target as Type; if (type == null) { throw new SterlingSerializerException( this, target.GetType()); } writer.Write(type.AssemblyQualifiedName); } /// /// Deserialize the object /// /// The type of the object /// A reader to deserialize from ///
The deserialized object
public override object Deserialize( Type type, BinaryReader reader) { return Type.GetType(reader.ReadString()); }}

 

转载于:https://www.cnblogs.com/Yukang1989/archive/2013/01/17/2864233.html

你可能感兴趣的文章
/tmp分区满,把oracle rac弄死了
查看>>
深入浅出linux系统umask值及其对应的文件权限讲解
查看>>
企业生产一线管理应找怎样的好帮手?
查看>>
MySQL数据库常用基本命令应用分享01
查看>>
实现线上高性能接口方案nginx负载tornado后端lua数据
查看>>
IT项目中存储设备的选型
查看>>
zabbix proxy配置文件不能把DBhost设置成远程数据库?
查看>>
疯狂ios之疯狂打飞机游戏(3)
查看>>
我的友情链接
查看>>
AWS的十年发展之路-永远前行
查看>>
Windows 2008 R2之三十六ADCS实现跨森林注册(二)
查看>>
最全团队管理手册
查看>>
浅谈在Linux中磁盘超出2T的管理方式
查看>>
安装Office 2010时1402错误的处理
查看>>
个人笔记ORA-32017 ORA-16179
查看>>
MSDE2000与SQLExpress2005共存时如何远程访问
查看>>
跨域组播---BGP+MSDP
查看>>
Microsoft Dynamics CRM server 2015 开发 之 安装visual studio 2012
查看>>
监控利器Nagios之二:Nagios的细致介绍和监控外部服务器的私有信息
查看>>
QoS技术入门(实操必须掌握的基本理论)
查看>>