public void Modify(string id) { using (var ctx = new PermissionDBEntities()) { users myusers = ctx.users.FirstOrDefault(u => u.userid == id); myusers.username = "******"; ctx.ApplyCurrentValues("users", myusers); int intAffected = ctx.SaveChanges(); ctx.AcceptAllChanges(); } }
public void Insert() { //create an instance belong to users var myusers = new users() { userid=Guid.NewGuid().ToString(), username="******", passwordword="123", name="张伟2", sex="男" }; //PermissionDBEntities is entity factory ,object-myusers can be created by PermissionDBEntities with dynmaic using (var ctx = new PermissionDBEntities()) { ctx.users.AddObject(myusers); ctx.SaveChanges(); } }