static void Main(string[] args) { //codefirst //MysqlDDLTextGenerator CodeFirst = new MysqlDDLTextGenerator(); //string createTableDDL = CodeFirst.CreateTable(typeof(Dictionary)); using (var dbContext = new WQSDbContext()) { var list = dbContext.Queryable <Dictionary>().Select().Where(d => d.DelFlag == 0).ToList(); } }
public void BaseOperation() { string newId = Guid.NewGuid().ToString().Replace("-", ""); using (var dbContext = new WQSDbContext()) { //Add dbContext.Add <Student>(new Student { Id = newId, StudentName = "王二", Age = 20 }); bool isExist = dbContext.Queryable <Student>().Select(s => s.Id).Where(s => s.Id.Equals(newId)).Any(); Assert.AreEqual(true, isExist); //update string name = Guid.NewGuid().ToString().Replace("-", ""); dbContext.Update <Student>(s => new { s.StudentName }, new Student { StudentName = name }).Where(s => s.Id.Equals(newId)).Done(); isExist = dbContext.Queryable <Student>().Select(s => s.Id).Where(s => s.StudentName.Equals(name)).Any(); Assert.AreEqual(true, isExist); //name = Guid.NewGuid().ToString().Replace("-", ""); //dbContext.Update<Student>(new Student { Id = newId, StudentName = name }); //isExist = dbContext.Queryable<Student>().Select(s => s.Id).Where(s => s.StudentName.Equals(name)).Any(); //Assert.AreEqual(true, isExist); //select name = Guid.NewGuid().ToString().Replace("-", ""); int insertCount = 5; for (int i = 0; i < insertCount; i++) { dbContext.Add <Student>(new Student { Id = Guid.NewGuid().ToString().Replace("-", ""), StudentName = name, Age = 20 }); } var list = dbContext.Queryable <Student>().Select(s => new { s.StudentName, s.Id }).Where(s => s.Age > 10 && s.StudentName.Equals(name)).Paging(1, 10).ToList(); Assert.AreEqual(insertCount, list.Count); //delete dbContext.Delete <Student>(s => s.Id.Equals(newId)); isExist = dbContext.Queryable <Student>().Select(s => s.Id).Where(s => s.Id.Equals(newId)).Any(); Assert.AreEqual(false, isExist); } }