代码之家  ›  专栏  ›  技术社区  ›  Jader Dias

是否可以使用Linq to SQL运行任意查询?C

  •  2
  • Jader Dias  · 技术社区  · 16 年前

    UPDATE [TB_EXAMPLE] SET [COLUMN1] = 1
    

    6 回复  |  直到 16 年前
        1
  •  8
  •   Marko andy    12 年前

    ExecuteQuery方法返回LINQ to SQL实体,因此您需要向其传递一个类型:

    [VB.Net]
    MyDataContext.ExecuteQuery(Of Product)("SELECT * FROM PRODUCTS")
    
    [C#]
    MyDataContext.ExecuteQuery<Product>("SELECT * FROM PRODUCTS");
    

    MyDataContext.ExecuteCommand("UPDATE Products WHERE ProductID = {0}",1) 
    

    MyDataContext.ExecuteCommand("UPDATE Products WHERE ProductID = 1") 
    
        2
  •  2
  •   tvanfosson    16 年前

    DataContext ExecuteCommand

    这种方法是一种传递

    该命令的语法几乎为 与用于创建的语法相同

        3
  •  1
  •   BFree    16 年前
    foreach(var TB_EXAMPLE ex dbDataContext.TB_EXAMPLES)
    {
       ex.COLUMN1 = 1;
    }
    
    dbDataContext.SubmitChanges();
    
        5
  •  1
  •   Björn    16 年前
    var row = (from t in dataContext.table
                where t.id==1
                select t).Single();
    row.columnName = 1;
    dataContext.SubmitChanges();
    

        6
  •  0
  •   bendewey    16 年前

    using (var ctx = new MyDataContext())
    {
      var customer = ctx.Customers.First();
      customer.Name = "New Name";
      ctx.SaveChanges();
    }
    

    http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executing-custom-sql-expressions.aspx

    推荐文章