ORM框架-VB/C#.Net实体代码生成工具(EntitysCodeGenerate) 新增与JSON和EString的交互
1、与JSON的交互
工具生成的实体提供ToJSON和FromJSON两个方法及相应实体集方法,可以方便实体对象、实体集对象与JSON内容直接相互转换。
示例代码如下所示:
employee e1 = new employee("A-C71970F");//得到主键为A-C71970F的对应数据 employee e2 = new employee("asd");//没有对应数据 employee entity1;
employeeS es = new employeeS(true);//获取全部数据 employeeS entitys; employeeS entitys1; employeeS entitys2;
entity1 = new employee(); string json1 = e1.ToJSON();//将实体信息转化为JSON文本 entity1 = entity1.FromJSON(json1);//从JSON文本中转化到实体
entitys = new employeeS(); entitys1 = new employeeS(); entitys2 = new employeeS(); entitys.Add(e1); entitys.Add(e2); string json3 = entitys.ToJSON(); entitys1 = entitys1.FromJSON(json3); //通用用法 entitys2.FromJSON(json3); //实体集专用用法
entitys1 = new employeeS(); entitys2 = new employeeS(); json3 = es.ToJSON(); entitys1 = entitys1.FromJSON(json3); //通用用法 entitys2.FromJSON(json3); //实体集专用用法 |
2、与String(即EString)的交互
工具生成的实体提供ToString和FromString两个方法及相应实体集方法,可以方便实体对象、实体集对象与String内容直接相互转换。
示例代码如下所示:
employee e1 = new employee("A-C71970F");//得到主键为A-C71970F的对应数据 employeeS es = new employeeS(true);//获取全部数据 employee entity1 = new employee(); employeeS entitys1 = new employeeS(); employeeS entitys2 = new employeeS(); string str1 = e1.ToString();//转化为字符串文本 entity1 = entity1.FromString(str1);//从字符串文本中实例化到实体 string strEntitys = es.ToString(); entitys1 = entitys1.FromString(strEntitys);//实体集通用用法 entitys2.FromString(strEntitys);//实体集专用用法 |
注:EString是针对实体/集 (亦即一维/二维数据)设计的,格式为键值对的形式出现,以键盘不能直接输入的单个生僻字符’┋’为分割符,对于集合类,以’┋┋’(即连续两个’┋’)为分割符(示例=>name┋value1┋┋name┋value2)。