ORM框架(ITDOS实战源码)

 ORM提供了实现持久化层的另一种模式,它采用映射元数据来描述对象关系的映射,使得ORM中间件能在任何一个应用的业务逻辑层和数据库层之间充当桥梁。

如以下示例:

 1  public int GetSystemAccreditMessageInfo(AccreditParam param)
 2         {
 3             var where = new Where<User>();
 4             var countMesage = 0;//记录提醒次数
 5             HttpCookie cookie = HttpContext.Current.Request.Cookies["UserLogin"] as HttpCookie;
 6             if (cookie["Login_id"] != null)
 7             {
 8                 where.And(d => d.id == cookie["Login_id"].ToString());
 9             }
10             where.And(d => d.Del_state == 0);
11             var fs = DB.Context.From<User>()
12                 .Select(User._.All, Power._.All)
13                 .InnerJoin<Power>((a, b) => a.Role_id == b.id)
14                 .Where(where);
15             if (fs.First().Authority == "0")
16             {
17                 countMesage = 0;
18             }
19             else if (fs.First().Authority == "1")
20             {
21                 countMesage = DB.Context.From<Accredit>().Where(d => d.OAuditor_signature == null || d.OAuditor_signature == "").Count();
22             }
23             else if (fs.First().Authority == "2")
24             {
25                 countMesage = DB.Context.From<Accredit>().Where(d => d.TAuditor_signature == null || d.TAuditor_signature == "").Count();
26             }
27             else if (fs.First().Authority == "3")
28             {
29                 countMesage = DB.Context.From<Accredit>().Where(d => d.OAuditor_signature == null || d.OAuditor_signature == "" || d.TAuditor_signature == null || d.TAuditor_signature == "").Count();
30             }
31             return countMesage;
32         }
 1 public BaseResult AddAccreditInfo(AccreditParam param)
 2         {
 3             var model = new Accredit();
 4             model.id = Guid.NewGuid().ToString();
 5             model.Acceptance_number = param.Acceptance_number;
 6             model.Certificate_number = param.Certificate_number;
 7             model.Issuing_office = param.Issuing_office;
 8             model.Issue_date = param.Issue_date;
 9             model.Effective_date = param.Effective_date;
10             model.Authorization_projectname = param.Authorization_projectname;
11             model.Measuring_range = param.Measuring_range;
12             model.Accuracy = param.Accuracy;
13             model.Organization_name = param.Organization_name;
14             model.Address = param.Address;
15             model.Corporate_representative = param.Corporate_representative;
16             model.Leading_person = param.Leading_person;
17             model.Competent_department = param.Competent_department;
18             model.Authorized_area = param.Authorized_area;
19             model.Authorization_form = param.Authorization_form;
20             model.Approver = param.Approver;
21             model.Input_person = param.Input_person;
22             model.Input_unit = param.Input_unit;
23             model.Acceptance_date = param.Acceptance_date;
24             HttpCookie cookie = HttpContext.Current.Request.Cookies["UserLogin"] as HttpCookie;
25             if (cookie["OrgId"] != null)
26             {
27                 model.OrgId = cookie["OrgId"].ToString();
28             }
29             if (cookie["OrgId"]=="63001c38-afa4-4a06-567d-0f39b6b5ca9b")
30             {
31                 model.Processing_state = 0;
32             }
33             model.Remarks = param.Remarks;
34             model.Del_state = 0;
35             model.Time = DateTime.Now;
36             //model.Processing_state = param.Processing_state;
37             model.brand = param.brand;
38             var count = DB.Context.Insert<Accredit>(model);
39             return new BaseResult(true, model, "", count);
40         }
 1  public BaseResult UptAccreditInfo(AccreditParam param)
 2         {
 3             var result = GetUpdateModel(param);
 4             if (!result.IsSuccess)
 5                 return result;
 6 
 7             var model = (Accredit)result.Data;
 8             model.Acceptance_number = param.Acceptance_number;
 9             model.Certificate_number = param.Certificate_number;
10             model.Issuing_office = param.Issuing_office;
11             model.Issue_date = param.Issue_date;
12             model.Effective_date = param.Effective_date;
13             model.Authorization_projectname = param.Authorization_projectname;
14             model.Measuring_range = param.Measuring_range;
15             model.Accuracy = param.Accuracy;
16             model.Organization_name = param.Organization_name;
17             model.Address = param.Address;
18             model.Corporate_representative = param.Corporate_representative;
19             model.Leading_person = param.Leading_person;
20             model.Competent_department = param.Competent_department;
21             model.Authorized_area = param.Authorized_area;
22             model.Authorization_form = param.Authorization_form;
23             model.Approver = param.Approver;
24             model.Input_person = param.Input_person;
25             model.Input_unit = param.Input_unit;
26             HttpCookie cookie = HttpContext.Current.Request.Cookies["UserLogin"] as HttpCookie;
27             if (cookie["OrgId"] != null)
28             {
29                 model.OrgId = cookie["OrgId"].ToString();
30             }
31             if (cookie["OrgId"] == "63001c38-afa4-4a06-567d-0f39b6b5ca9b")
32             {
33                 model.Processing_state = 0;
34             }
35             model.Acceptance_date = param.Acceptance_date;
36             model.Remarks = param.Remarks;
37             model.Del_state = 0;
38             //model.Processing_state = param.Processing_state??model.Processing_state;
39             model.Time = DateTime.Now;
40             model.brand = param.brand;
41             var count = DB.Context.Update(model, d => d.id == param.id);
42             return new BaseResult(true, model, "", count);
43         }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏跟着阿笨一起玩NET

C#自定义泛型类绑定ComboBox控件

C# WinForm ComboBox 自定义数据项 (ComboBoxItem )

1391
来自专栏码字搬砖

httpClient 发送压缩文件

1533
来自专栏飞扬的花生

.net服务器端发起请求封装

1354
来自专栏菩提树下的杨过

几种常见复合sql查询语句的linq写法[继续补充中]

1.IN 语句 尝试了很多次,好象linq死活不生成in语句,无奈只能做了下变换 例,要找出"手机大类"以及"手机下属所有子类"的产品 (手机大类的ID为D0...

2116
来自专栏王磊的博客

Net连接mysql的公共Helper类MySqlHelper.cs带MySql.Data.dll下载

MySqlHelper.cs代码如下: using System; using System.Collections.Generic; using System...

4459
来自专栏c#开发者

让web api 4.5支持Jquery.getJson(url,handle)跨域访问

代码片段,google了半天,找到的都是4.5 rc,或之前版本的代码,发现都不能用,正式版后有些方法做了修改。我重新修改一下分享给大家 public stat...

2685
来自专栏跟着阿笨一起玩NET

【经典示例分享】— 商城购物车设计(VS+Access)附源码

弹指一挥间,从事开发工作两年多了,工作记录文件夹不知不觉好几G了。今天分享下之前项目中用到的一个购物车示例,虽然用的技术比较老(拖放控件DataGview),我...

2232
来自专栏hbbliyong

.Net下SQLite的DBHelp

怎样获取SqLite请参考初识SqlLite ---.net连接数据库,怎样在SQLite使用Linq请参考在C#中利用Nuget包使用SQLite数据库和Li...

2754
来自专栏大内老A

开发自己的Data Access Application Block[下篇]

上接:[原创] 我的ORM: 开发自己的Data Access Application Block - Part I 4. Database 下面来介绍重中之重...

2246
来自专栏yl 成长笔记

从数据库中下载文件的工具

552

扫码关注云+社区