Пример #1
0
        public void Register(string registerJson)
        {
            RegisterInfo registerInfo = JsonConvert.DeserializeObject <RegisterInfo>(registerJson);

            using (var odb = OdbFactory.Open(UserInfoDB))
            {
                var users = from user in odb.AsQueryable <UserInfo>()
                            where
                            user.Username.Equals(registerInfo.Username)
                            select user;

                RegisterResult registerResult = new RegisterResult();
                if (users.Count() > 0)
                {
                    Console.WriteLine("用户已经{0}注册...", registerInfo.Username);
                    registerResult.Result = "Fail";
                }
                else
                {
                    //odb.Store<UserInfo>(registerInfo);
                    odb.Store(registerInfo);
                    Console.WriteLine("用户{0}成功注册...", registerInfo.Username);
                    registerResult.Result = "Success";
                }
                string registerResultJson = JsonConvert.SerializeObject(registerResult);
                SendCommand("RegisterResult", registerResultJson);
            }
        }
Пример #2
0
        public static void Main1(string[] args)
        {
            RegisterInfo registerInfo = new RegisterInfo("mchcylh", "mchcylh");
            string       filename     = "test.db";

            using (var odb = OdbFactory.Open(filename))
            {
                odb.Store(registerInfo);
            }

            using (var odb = OdbFactory.Open(filename))
            {
                var query = odb.Query <UserInfo>();
                query.Descend("Username").Constrain("mchcylh").Equal();
                var users = query.Execute <UserInfo>();

                foreach (var user in users)
                {
                    Console.WriteLine(user);
                }
            }
            Console.ReadLine();
        }