EF框架
Linq to EF
添加:
//用户注册
int IUserDAO.Register(Users user)
{
int uid = ;
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
EF.DD_Users entity = new EF.DD_Users()
{
UserName = user.UserName,
Password = user.Password,
RegistTime = user.RegistTime,
CartLevel = user.CartLevel,
GradeID = user.GradeID,
GoldBalance = user.GoldBalance,
NickName = user.NickName,
State=user.State,
UserNameType=user.UserNameType
};
context.DD_Users.Add(entity);
context.SaveChanges();
uid = entity.UID;
}
return uid;
}
修改:
//用户修改
bool IUserDAO.EditUser(Users u)
{
bool flag = false;
using( EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
var user = context.DD_Users.SingleOrDefault(a =>a.UID == u.UID);
if (user != null)
{
user.Birthday = u.Birthday;
user.Gender = u.Gender;
user.IDNumber = u.IDNumber;
user.NickName = u.NickName;
user.PersonalIDType = u.PersonalIDType;
user.Industry = u.Industry;
user.Professional = u.Professional;
user.RealName = u.RealName;
user.AddressID = u.AddressID;
user.Address = u.Address;
flag=context.SaveChanges()>?true:false;
}
}
return flag;
}
用户查询:
//用户登录
Users IUserDAO.Login(string loginid, string password)
{
Users user = null;
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
var entity = context.DD_Users.FirstOrDefault(u => u.UserName == loginid && u.Password == password);
if (entity != null)
{
user = CreatUser(user, entity);
}
}
return user;
} private static Users CreatUser(Users user, EF.DD_Users entity)
{
user = new Users()
{
UserName = entity.UserName,
UID = entity.UID,
Birthday = entity.Birthday,
GradeID = entity.GradeID,
Email = entity.Email,
CartLevel = entity.CartLevel,
GoldBalance = entity.GoldBalance,
IDBackImage = entity.IDBackImage,
IDFrontImage = entity.IDFrontImage,
IDNumber = entity.IDNumber,
LastAddressID = entity.LastAddressID,
LastInvoiceTypeID = entity.LastInvoiceTypeID,
PersonalIDType = entity.PersonalIDType,
LastLoginTime = entity.LastLoginTime,
Mobile = entity.Mobile,
NickName = entity.NickName,
Password = entity.Password,
RealName = entity.RealName,
RegistTime = entity.RegistTime,
State = entity.State,
UserNameType=entity.UserNameType,
Gender = entity.Gender,
Address = entity.Address,
Industry = entity.Industry,
Professional = entity.Professional,
IsVolunteer=entity.IsVolunteer,
HeadImage=entity.HeadImage,
AddressID=entity.AddressID
};
return user;
}
删除:
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
var user= context.Users.Where(c => c.Uid== ).First();
context.Users.Remove(user);
context.SaveChanges();
}
查询返回集合
List<InspectionUsers> IProductQualityDAO.GetAllInspection()
{
List<VIEWMODEL.InspectionUsers> inspectionUsers = null;
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{ inspectionUsers = (from f in context.DD_InspectionUsers
select new VIEWMODEL.InspectionUsers
{
INSID = f.INSID,
UserName = f.UserName,
Password = f.Password,
Mobile = f.Mobile,
Email = f.Email,
Telephone = f.Telephone,
RealName = f.RealName,
Birthday = f.Birthday,
PersonalIDType = f.PersonalIDType,
IDNumber = f.IDNumber,
IDFrontImage = f.IDFrontImage,
IDBackImage = f.IDBackImage,
CredentialTypeName = f.CredentialTypeName,
CredentialNumber = f.CredentialNumber,
CredentialFrontImage = f.CredentialFrontImage,
CredentialBackImage = f.CredentialBackImage,
Grade = f.Grade,
RegistTime = f.RegistTime,
LastLoginTime = f.LastLoginTime,
LastInspectTime = f.LastInspectTime,
Professional = f.Professional,
INDIDS = f.INDIDS
}).ToList();
}
return inspectionUsers;
}
EF多表联查
List<ProductInspections> IProductQualityDAO.GetProductsByINSID(int INSID)
{ List<ProductInspections> list =new List<ProductInspections>();
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
list = (from pi in context.DD_ProductInspections
join p in context.DD_Products on pi.ProductID equals p.PID
join psp in context.DD_ProductStylePrices on pi.ProductID equals psp.PID
where pi.InspectorID == INSID
select new ProductInspections
{
ID=pi.ID,
InspectImgUrl=pi.InspectImgUrl,
InspectorID = pi.InspectorID,
InspectTime=pi.InspectTime,
ProductID=pi.ProductID,
Report=pi.Report,
ReportingTime=pi.ReportingTime,
Score=pi.Score,
ProductPrice=psp.Price,
ProductImageUrl=pi.InspectImgUrl,
ProductName = p.ProductName,
PRID = psp.PRID
}).ToList();
}
return list;
}
EF的二次查询(自己胡乱叫的名字)
IList<SubOrders> IOrderDAO.GetSubOrders(int uid)
{
List<SubOrders> list = new List<SubOrders>();
using (EF.ddgwDBEntities content = new EF.ddgwDBEntities())
{
var entities = content.DD_MainOrders.Where(o => o.UserID == uid);
foreach (var e in entities)
{
var collection = content.DD_SubOrders.Where(o => o.MOID == e.MOID).ToList();
foreach (var l in collection)
{
SubOrders s = new SubOrders();
s.MOID = l.MOID;
s.PID = l.PID;
s.PRID = l.PRID;
s.SenderID = l.SenderID;
s.SendTime = l.SendTime;
s.ShopsID = l.ShopsID;
s.SOID = l.SOID;
s.SubCoins = l.SubCoins;
s.Subtotal = l.Subtotal;
s.HasSent = l.HasSent;
s.HasShowed = l.HasShowed;
s.BuyingTime = l.BuyingTime;
s.DeliveryCost = l.DeliveryCost;
s.DeliveryMethod = l.DeliveryMethod;
s.HasApplyedReparing = l.HasApplyedReparing;
s.HasApplyedReplacing = l.HasApplyedReplacing;
s.HasApplyedReturning = l.HasApplyedReturning;
s.HasComment = l.HasComment;
s.HasReceived = l.HasReceived;
s.IsFreeCost = l.IsFreeCost;
s.Quantity = l.Quantity;
s.ReceiveTime = l.ReceiveTime;
s.UnitPrice = l.UnitPrice;
list.Add(s);
}
}
}
//查询完后还可继续联查
using (EF.ddgwDBEntities context = new EF.ddgwDBEntities())
{
foreach (var o in list)
{
EF.DD_ProductStylePrices productStylePrices = context.DD_ProductStylePrices.Single(a => a.PRID == o.PRID);
o.ImgUrl = context.DD_ProductImages.Where(p => p.PID == o.PID && productStylePrices.StyleJson.Contains("," + p.pGroupNo + ",")).ToList()[].Path;
o.ProductName = context.DD_Products.FirstOrDefault(p => p.PID == o.PID).ProductName;
}
}
return list;
}
EF框架的更多相关文章
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(24)-权限组的设计和实现(附源码)(终结)
ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo (3):面向接口编程 (4 ):业务逻辑层的封装 ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo (3):面向接口编程 (4 ):业务逻辑层的封装 ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(22)-为用户设置角色
ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo (3):面向接口编程 (4 ):业务逻辑层的封装 ...
- EF框架的三种工作方式
EF框架step by step(1)—Database-First EF框架step by step(2)—Model-First EF框架step by step(3)—Code-First 通过 ...
- C# CodeFirst(EF框架)代码优先创建数据库
namespace WebEF.Model{ public class ModelContext:DbContext //继承DBcontext 来自EF框架 { public ModelContex ...
- EF框架学习手记
转载: [ASP.NET MVC]: - EF框架学习手记 1.EF(Entity Framework)实体框架EF是ADO.NET中的一组支持开发面向数据的软件应用程序的技术,是微软的一个ORM框架 ...
- EF框架之三种模式
使用EF之前必须要对EF有个宏观的了解.学习任何一种技术都要像门卫一样问几个问题. 第一,它是谁? 第二,从哪里来? 第三,到哪里去? 默念一遍:不谋全局者,不足谋一域. Entity Framewo ...
- EF框架step by step(7)—Code First DataAnnotations(2)
上一篇EF框架step by step(7)—Code First DataAnnotations(1)描述了实体内部的采用数据特性描述与表的关系.这一篇将用DataAnnotations描述一下实体 ...
- EF框架step by step(7)—Code First DataAnnotations(1)
Data annotation特性是在.NET 3.5中引进的,给ASP.NET web应用中的类提供了一种添加验证的方式.Code First允许你使用代码来建立实体框架模型,同时允许用Data a ...
- EF框架step by step(5)—处理实体简单属性
EF框架会对实体进行跟踪,对实体的每个属性当前值和原始值及其状态进行跟踪,记录.当前值是指实体属性当前的被赋予的值,而原始值是指实体最初从数据库读取或者附加到DbContext时的值. 先通过简单的代 ...
随机推荐
- Python3下的paramiko模块
paramiko模块是基于Python实现的SSH远程安全连接,用于SSH远程执行命令.文件传输等功能. 默认Python没有,需要手动安装:pip install paramiko SSH密码认证远 ...
- mysql在linux下的安装与优化
mysql5.6 http://www.cnblogs.com/bookwed/p/5896619.html mysql5.7 http://blog.csdn.net/wb96a1007/artic ...
- pch文件的创建与配置
1.ios中pch文件的创建与配置 1.1 ios中pch文件的创建与配置 1.2 全局宏定义标志的配置 2.宏定义 这里放的主要是开发中常用的宏定义. /** 动态的字符串格式化宏 */ #defi ...
- Mybatis基于代理Dao实现CRUD操作 及 Mybatis的参数深入
Mybatis基于代理Dao实现CRUD操作 使用要求: 1.持久层接口和持久层接口的映射配置必须在相同的包下 2.持久层映射配置中mapper标签的namespace属性取值必须是持久层接口的全限定 ...
- asp web.config文件里compilation的assemblies add的元素来自哪里
该程序集组合由版本.区域性和公钥标记组成. ASP.NET 首先在应用程序的专用 Bin 目录中搜索程序集 DLL,然后在系统程序集缓存中搜索程序集 DLL. add 元素添加要在动态资源编译期间使用 ...
- #6432. 「PKUSC2018」真实排名(组合数学)
题面 传送门 题解 这数据范围--这输出大小--这模数--太有迷惑性了-- 首先对于\(0\)来说,不管怎么选它们的排名都不会变,这个先特判掉 对于一个\(a_i\)来说,如果它不选,那么所有大于等于 ...
- Linux根目录结构
1: bin目录 此目录存放所有二进制命令(用户) 2: boot目录 Linux内核及引导系统程序所需的目录 3: dev目录 所有设备文件的目录(如声卡.磁盘.光驱) 4: etc目录 二 ...
- P3241 [HNOI2015]开店 动态点分治
\(\color{#0066ff}{ 题目描述 }\) 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱. 这样的想 ...
- Python数组(一)
一.索引 数组中的索引(下标)是从0开始递增的,你可以像下面这样使用编号来访问各个元素: test=['java','C#','C++','html','Spring'] print(test[0]) ...
- filter防止xxs攻击
什么是XSS攻击? XSS攻击使用Javascript脚本注入进行攻击 例如在表单中注入: <script>location.href='http://www.itmayiedu.com' ...