You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using PEIS.Model;
|
|
|
|
|
|
|
|
|
|
namespace PEIS.Helper
|
|
|
|
|
{
|
|
|
|
|
class EntityFrameworkTemplate
|
|
|
|
|
{
|
|
|
|
|
private readonly lisdbEntities _db = new lisdbEntities();
|
|
|
|
|
public void Add()
|
|
|
|
|
{
|
|
|
|
|
_db.Dict_User.Add(new Dict_User()
|
|
|
|
|
{
|
|
|
|
|
UserName = "李进才",
|
|
|
|
|
Password = "test"
|
|
|
|
|
});
|
|
|
|
|
_db.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
public void Remove()
|
|
|
|
|
{
|
|
|
|
|
_db.Dict_User.RemoveRange(_db.Dict_User.Where(p => p.UserCode == "0001"));
|
|
|
|
|
_db.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
public void Edit()
|
|
|
|
|
{
|
|
|
|
|
var user = _db.Dict_User.Find("0001");
|
|
|
|
|
// 只能逐个赋值,不能直接赋值对象,除非写个方法类循环逐个赋值
|
|
|
|
|
user.UserName = "修改名字";
|
|
|
|
|
_db.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
public Dict_User SelectForId()
|
|
|
|
|
{
|
|
|
|
|
return _db.Dict_User.Find("0001");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Dict_User SelectForOther()
|
|
|
|
|
{
|
|
|
|
|
return _db.Dict_User.FirstOrDefault(p=>p.UserName=="管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Dict_User> SelectToList()
|
|
|
|
|
{
|
|
|
|
|
return _db.Dict_User.Where(p => p.UserName == "0001" || p.UserName == "管理员").ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|