您的位置:首页 > 新闻 > 热点要闻 > 淘宝运营规则_济南建设招标投标协会_软文标题和内容_seo搜索引擎官网

淘宝运营规则_济南建设招标投标协会_软文标题和内容_seo搜索引擎官网

2025/1/8 12:14:29 来源:https://blog.csdn.net/qq_51965854/article/details/143134274  浏览:    关键词:淘宝运营规则_济南建设招标投标协会_软文标题和内容_seo搜索引擎官网
淘宝运营规则_济南建设招标投标协会_软文标题和内容_seo搜索引擎官网

在这里插入图片描述

#region 常用取值 查询List<string> isName = new List<string> { "第一", "第二", "第三", "第四" };
List<string> result = isName.Where(m => m == "第三").ToList();MyDBContext myDB=new MyDBContext();
var lstUsers = myDB.UserT.Where(e => e.userName == "lisi").ToList();
Console.WriteLine(lstUsers.ToString());#endregion#region c#查询语法糖
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=localhost;Database=TestDB;Trusted_Connection=true;";
conn.Open();SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText =$"select * from userT where userName='{"lisi"}'";SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;DataSet dataSet = new DataSet();
adapter.Fill(dataSet);conn.Close();
#endregion#region c#修改删除新增语法糖
SqlConnection sqlupdate = new SqlConnection();
sqlupdate.ConnectionString = "Server=localhost;Database=TestDB;Trusted_Connection=true;";
sqlupdate.Open();
//SqlCommand commandUpdate = new SqlCommand("update userT set password='111' where  userName='lisi'",sqlupdate);
SqlCommand commandUpdate = new SqlCommand("delete userT where  userName is null", sqlupdate);
int count =commandUpdate.ExecuteNonQuery();sqlupdate.Close();#endregion#region EF6语法糖
userEntity user = new userEntity();using (MyDBContext mydb=new MyDBContext())
{user = mydb.UserT.FirstOrDefault(e => e.userName == "lisi" && e.password == "123");
}
using (MyDBContext mydb=new MyDBContext())
{mydb.UserT.Attach(user);mydb.Entry(user).State = System.Data.Entity.EntityState.Modified;user.password = "666";mydb.SaveChanges(); 
}
#endregion#region 单表查询
using (MyDBContext myDB = new MyDBContext())
{var query = from usert in myDB.UserTselect new userEntityNew{userName = usert.userName,password = usert.password,nickName = usert.nickName};List<userEntityNew> users = query.ToList();Console.ReadLine();
}
#endregion#region EF6联表查询
//into utus from user_scores in utus.DefaultIfEmpty() 等于 left out join
using (MyDBContext myDB = new MyDBContext())
{var query = from usert in myDB.UserTjoin user_scores in myDB.UserScoreson usert.ID equals user_scores.userId into utusfrom user_scores in utus.DefaultIfEmpty()select new userAndscores{userName = usert.userName,nickName = usert.nickName,math = user_scores.math,english = user_scores.english,chinese = user_scores.chinese,};List<userAndscores> userScores = query.ToList();Console.ReadLine();}
using (MyDBContext myDB = new MyDBContext())
{var query = from usert in myDB.UserTjoin user_scores in myDB.UserScoreson usert.ID equals user_scores.userId into utusfrom user_scores in utus.OrderByDescending(e => e.math).Take(1).DefaultIfEmpty()select new userAndscores{userName = usert.userName,nickName = usert.nickName,math = user_scores.math,english = user_scores.english,chinese = user_scores.chinese,};List<userAndscores> userScores = query.ToList();Console.ReadLine();
}
#endregion

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com