MVC 增 、删、 改、查
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
RbacDBEntities db = new RbacDBEntities();
var roles1 = from r in db.Roles
where r.Name.Contains("主任")
select r;
var roles2 = db.Roles
.Where(p => p.Name.Contains("主任"))
.Select(p => p).ToList();
string sql = @"select * from roles where name like '%主任%'";
db.Database.SqlQuery<Role>(sql);
db.SaveChanges();
List<cp_select_role_Result> roles11= db.cp_select_role("主任").ToList();
Console.Read();
}
public static void Delete()
{
RbacDBEntities db = new RbacDBEntities();
Role r1 = db.Roles.Find(1074);
db.Roles.Remove(r1);
db.SaveChanges();
Role r2 = new Role()
{
ID = 1075
};
db.Entry(r2).State = System.Data.Entity.EntityState.Deleted;
db.SaveChanges();
string sql = @"delete roles where id=1076";
db.Database.ExecuteSqlCommand(sql);
db.SaveChanges();
db.cp_delete_role(1077);
Console.Read();
}
改
public static void Edit()
{
RbacDBEntities db = new RbacDBEntities();
Role r1 = db.Roles.Find(1074);
r1.Name = "修改1";
r1.Remark = "修改备注1";
db.SaveChanges();
Role r2 = new Role()
{
ID = 1075,
Name = "修改2",
Remark = "修改备注2"
};
db.Entry(r2).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
string sql = @"update roles set name='修改3',remark='修改备注3' where id=1076";
db.Database.ExecuteSqlCommand(sql);
db.SaveChanges();
db.cp_update_role(1077, "修改4", "修改备注4");
Console.Read();
}
public static void ADD()
{
RbacDBEntities db = new RbacDBEntities();
Role r1 = new Role()
{
Name = "方式1",
Remark = "备注1"
};
db.Roles.Add(r1);
db.SaveChanges();
Role r2 = new Role()
{
Name = "方式2",
Remark = "备注2"
};
db.Entry(r2).State = System.Data.Entity.EntityState.Added;
db.SaveChanges();
string sql = @"insert into roles values('方式3','备注3')";
db.Database.ExecuteSqlCommand(sql);
db.SaveChanges();
db.cp_insert_role("方法4", "备注4");
Console.Read();
}
}
}