zoukankan      html  css  js  c++  java
  • EF基本操作

    一、 EF分页查询

     1 #region EF分页
     2 static void UserPagingQuery (int page, int pageSize) {
     3     var p = page == 0 ? 0 : (page - 1) * pageSize;
     4     DemoDbEntities db = new DemoDbEntities ();
     5     //在分页前先要是用OrderBy或者OrderByDescending对数据进行正序或者倒序
     6     //然后在skip()跳过多少条,take()查询多少条。
     7     db.User.OrderBy (u => u.ID)
     8         .Skip (p)
     9         .Take (pageSize)
    10         .ToList ()
    11         .ForEach (c => Console.WriteLine (c.ID));
    12 }
    13 #endregion
    View Code

    二、EF中执行SQL

     1 #region EF中执行SQL语句
     2 
     3 static void EFExecuteSql () {
     4     DemoDbEntities db = new DemoDbEntities ();
     5     string sql = "update [DemoDb].[dbo].[User] set NAME=@name where ID>@id";
     6 
     7     SqlParameter[] p = new SqlParameter[] {
     8         new SqlParameter ("@id", 5),
     9         new SqlParameter ("@name", "王五")
    10     };
    11     db.Database.ExecuteSqlCommand (sql, p);
    12     Console.WriteLine ("修改成功");
    13 }
    14 
    15 #endregion
    View Code
  • 相关阅读:
    poj 1080 dp
    Codeforces Round #280 (Div. 2)
    Codeforces Round #279 (Div. 2)f
    Codeforces Round #278 (Div. 1)
    Codeforces Round #276 (Div. 1)
    搜索
    debug 心得
    ZOJ 1633
    DRF 一对多序列化与反序列化
    HTTP协议
  • 原文地址:https://www.cnblogs.com/IIXS/p/11234032.html
Copyright © 2011-2022 走看看