Example #1
0
        static void Main(string[] args)
        {
            UserController contoller = new UserController();
            BusinessController contollerCom = new BusinessController();

            //insert
            string _guid0 = Guid.NewGuid().ToString();
            var myusers = new users(){
                userid = _guid0,username = "******",passwordword = "1",name = "0a",sex = "男"
            };
            Console.WriteLine("after insert:" + _guid0);
            contollerCom.Insert<users>(myusers);
            Console.WriteLine(contoller.print(contollerCom.Get<users>("userid", _guid0)));

            var myuserLists = new List<users>{
                new users(){userid = Guid.NewGuid().ToString(),username = "******",passwordword = "1",name = "1a"},
                new users(){userid = Guid.NewGuid().ToString(),username = "******",passwordword = "1",name = "2a"}
            };
            Console.WriteLine("after insert many:");            ;
            Console.WriteLine(contollerCom.InsertList<users>(myuserLists));

            //update
            List<users> mylist = contollerCom.Get<users>(u => u.username == "0");
            var curUser = mylist.First<users>();
            Console.WriteLine("before update:" + curUser.userid);
            Console.WriteLine(contoller.print(curUser));
            curUser.username = "******";
            contollerCom.Update<users>(curUser, "userid");
            Console.WriteLine("after update:" + curUser.userid);
            Console.WriteLine(contoller.print(contollerCom.Get<users>(u => u.username == "0axiugai")));
            //manual update
            Console.WriteLine("manual update:" + curUser.userid);
            contoller.Modify(curUser.userid);
            Console.WriteLine(contoller.print(contollerCom.Get<users>(u => u.userid == curUser.userid)));

            //delete
            Console.WriteLine("delete all:" + _guid0);
            contollerCom.Delete<users>("userid", _guid0);
            Console.WriteLine(contoller.print(contollerCom.Get<users>("select * from users ")));
            Console.WriteLine("delete u.sex==男:");
            contollerCom.Delete<users>(u=>u.sex=="男");
            Console.WriteLine(contoller.print(contollerCom.Get<users>("select * from users ")));

            //select
            Console.WriteLine("select all:");
            Console.WriteLine(contoller.print());
            Console.WriteLine("select * from users where username='******'");
            Console.WriteLine(contoller.print(
                contollerCom.Get<users>("select * from users where username='******'")
                ));
            Console.WriteLine("u=>u.username==1");
            Console.WriteLine(contoller.print(
                contollerCom.Get<users>(u => u.username == "1a")
                ));

            Console.ReadKey();
        }
 public void Insert2()
 {
     //create an instance belong to users
     var myusers = new users()
     {
         userid = Guid.NewGuid().ToString(),
         username = "******",
         passwordword = "123",
         name = "张伟2",
         sex = "男"
     };
     BusinessController contoller = new BusinessController();
     contoller.Insert<users>(myusers);
 }
 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();
     }
 }
 public string print(users u)
 {
     return "id:" + u.userid + "\tname:" + u.name + "\tusername:" + u.username;
 }
Example #5
0
        private void Fixupusers(users previousValue)
        {
            if (previousValue != null && previousValue.userrole.Contains(this))
            {
                previousValue.userrole.Remove(this);
            }

            if (users != null)
            {
                if (!users.userrole.Contains(this))
                {
                    users.userrole.Add(this);
                }
                if (userid != users.userid)
                {
                    userid = users.userid;
                }
            }
            else if (!_settingFK)
            {
                userid = null;
            }
        }