private static void SendRemind(User user, string title, string Content, MyDB db) { User sender = db.Users.First(u => u.Code.Equals("remindRobot")); //后台模拟用户 Info info = new Info() { ID = Guid.NewGuid().ToString(), Title = "[提醒]"+title, Content = Content, CreateDate = DateTime.Now, SendDate = DateTime.Now, Creator = sender, SendTypes = "", Type = "提醒", Receivers = new InfoInbox[] { new InfoInbox { ID = Guid.NewGuid().ToString(), Receiver = user, ReceiveTypes = "" } } }; db.Infos.Add(info); }
public string Index() { string userCode = Request.Form["user"]; string password = Request.Form["pwd"]; string title = Request.Form["title"]; string content = Request.Form["content"]; string to = Request.Form["to"]; Response.Clear(); Response.ContentType = "text/xml"; string infoID = Guid.NewGuid().ToString(); using (MyDB mydb = new MyDB()) { EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password); if (user != null) { EntityObjectLib.Info info = new Info { ID = infoID, Title = title, Content = content, CreateDate = DateTime.Now, SendDate = DateTime.Now, Creator = user, SendTypes = "", Receivers = new EntityObjectLib.InfoInbox[] { new EntityObjectLib.InfoInbox { ID = Guid.NewGuid().ToString(), Receiver = mydb.Users.Find(to), ReceiveTypes = "" } } }; mydb.Infos.Add(info); mydb.SaveChanges(); return(CJX.Object2XML(new { result = true }).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } }
// // GET: http://localhost:12480/msgService/getMyMessages?user=chw&pwd=123456&type=&start=1&length=10 /// <summary> /// 取我的指定类别的全部消息 /// 其中type,start,length可选,缺省:type为全部类型,start为零,length为100 /// type:"UR"," /// </summary> /// <returns></returns> public string Index() { List <Expression <Func <EntityObjectLib.Info, bool> > > expressions = new List <Expression <Func <EntityObjectLib.Info, bool> > >(); string userCode = Request.QueryString["user"]; string password = Request.QueryString["pwd"]; string type = Request.QueryString["type"]; if (!string.IsNullOrEmpty(type)) { expressions.Add(info => info.Type == type); } int start = Request.QueryString["start"] == null || string.IsNullOrEmpty(Request.QueryString["start"]) ? 1 : int.Parse(Request.QueryString["start"]); int length = Request.QueryString["length"] == null || string.IsNullOrEmpty(Request.QueryString["length"]) ? 100 : int.Parse(Request.QueryString["length"]); Response.Clear(); Response.ContentType = "text/xml"; using (MyDB mydb = new MyDB()) { EntityObjectLib.User user = mydb.Users.First(u => u.Code.ToLower() == userCode.ToLower() && u.Password == password); if (user != null) { IQueryable <Info> infos = mydb.InfoInboxs .Where(ib => ib.Receiver.ID == user.ID) .Select(ib => ib.Info) .OrderByDescending(info => info.CreateDate); foreach (Expression <Func <EntityObjectLib.Info, bool> > expression in expressions) { infos = infos.Where(expression); } return(CJX.Object2XML( infos.Skip(start - 1).Take(length).Select(info => new { info.ID, info.Title, Creator = info.Creator.Name, info.CreateDate, Files = mydb.InfoFiles.Count(f => f.Info.ID == info.ID) }) .ToList() .Select(info => new { info.ID, info.Title, info.Creator, CreateDate = info.CreateDate.ToString("yyyy-M-d H:m:s"), info.Files }) .ToArray() ).OuterXml); } else { return("<?xml version=\"1.0\"?><root><error>用户名口令错误!</error></root>"); } } }
public void TestMethod1() { using (MyDBExt db = new MyDBExt()) { //db.Configuration.LazyLoadingEnabled = true; //DbSet<LinkMethod> lmss = db.Set<LinkMethod>(); //lmss.Create(); //IQueryable<LinkMethod> lmsOld = ext.Set(typeof(LinkMethod)); // 错误信息:实体类型LinkMethod不是当前上下文db的模型的一部分 Expression<Func<LinkMethod,LinkMethod>> d2 = p => p; IQueryable<LinkMethod> lmsOld = db.LinkMethods.Select(d2); // 单向关联,反向查询 // p.LinkMethods 等价于 db.LinkMethods.Where(l => l.user.ID.Equals(p.ID)) 或者 db.LinkMethods.Where(l => l.user == p) //IQueryable<User> test = db.Users.Where(p => db.LinkMethods.Where(l => l.user == p).Count() > 0); IQueryable test = db.Users.Select(p => db.LinkMethods.Where(l => l.user == p).Select(l => l) ); IQueryable test1 = db.Users.Select(p =>new {p.Name,p.Code, p.Roles }); //IQueryable<User> test = db.Users.Where(p => p.LinkMethods(db).Where(l => l.user == p).Count() > 0); //IQueryable test = db.Users.Select(p => p.Roles); //IQueryable<LinkMethod> lmsOld = lmss.Select(p => p); foreach (LinkMethod lm in lmsOld) { db.LinkMethods.Remove(lm); //db.Set<LinkMethod>().Remove(lm); } //ext.SaveChanges(); User userOld = db.Users.FirstOrDefault(p => p.Code.Equals("xiongxiong")); if (userOld != null) { db.Users.Remove(db.Users.FirstOrDefault(p => p.Code.Equals("xiongxiong"))); } User u = new User(); u.ID = Guid.NewGuid().ToString(); u.Code = "xiongxiong"; u.Name = "雄"; u.Password = "******"; db.Users.Add(u); LinkMethod lm1 = new LinkMethod(); lm1.ID = Guid.NewGuid().ToString(); lm1.MethodType = "A"; lm1.Content = "content"; lm1.user = u; db.LinkMethods.Add(lm1); //db.Set<LinkMethod>().Add(lm1); db.SaveChanges(); IQueryable<LinkMethod> lms = db.Set<LinkMethod>().Select(p => p); //IQueryable<User> users = ext.Users.Select(p => p); //ICollection<LinkMethod> lms1 = users.Select(p => p.getLinkMethodsByUser()); } }
public void rrr() { MyDB mydb = new MyDB(); mydb.Users.Load(); IEnumerable<User> us2 = mydb.Users.Local.Where(u => 1==1); User user1 = mydb.Users.First(u => u.Code.Contains("lxx")); user1.Name = "asdfasdfasdf"; User nu = new User { ID = Guid.NewGuid().ToString(), Code = "lxx" }; mydb.Users.Add(nu); MyDB mydb1 = new MyDB(); User user3 = mydb1.Users.First(u => u.Code.Contains("lxx")); user3.MSN = "wwwwwwwwwwwwww"; User user2 = mydb.Users.First(u => u.Code.Contains("lxx")); user2.MSN = "ssssssssssssssss"; //mydb.Users.Remove(user2); IEnumerable<User> us1 = mydb.Users.Where(u => 1==1); }
public static IEnumerable<Organization> getOrganizationsByUser(User current, MyDB mydb) { List<Organization> result = new List<Organization>(); Organization org = current.Organization; while (org != null) { result.Add(org); org = org.Parent; } return result; }