Linq toEntity 从表中删除特定列

发布于 2024-12-21 07:10:19 字数 445 浏览 3 评论 0原文

Linq to 实体查询通过匹配条件从表中删除特定列

`

public ActionResult deleteChecks(string checkValue)
    {
        check_master checks = (from table in db.check_master
                              where table.check_code == checkValue
                              select table).First();
        //now how to delete/remove checks.mcheck

        return View("Edit");
    }`

只想更新表 check_master 中具有空值(所选行)的单个列元素

Linq to entity query to delete a specific column from a table by matching a condition

`

public ActionResult deleteChecks(string checkValue)
    {
        check_master checks = (from table in db.check_master
                              where table.check_code == checkValue
                              select table).First();
        //now how to delete/remove checks.mcheck

        return View("Edit");
    }`

Only want to update a single column element with null value(of selected row) from the table check_master

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老娘不死你永远是小三 2024-12-28 07:10:19

您可以将单个属性(映射到列)设置为 null 并将其保存到数据库

foreach(check_master check in checks)
{
   check.mcheck = null;
}

db.SaveChanges();

You can set a single property (which maps to a column) to null and save it to the database

foreach(check_master check in checks)
{
   check.mcheck = null;
}

db.SaveChanges();
时光倒影 2024-12-28 07:10:19
using (NorthwindDataContext db = new NorthwindDataContext())

{

// Retrieve the existing entity. Database Call 1

Product product = db.Products.First(p => p.ProductID == 1);



// Change the properties. LINQ to SQL knows

// these specific properties have changed.

product.UnitsInStock = 14;



// Flush the changes. Database Call 2

db.SubmitChanges();

}

using (NorthwindDataContext db = new NorthwindDataContext())

{

// Retrieve the existing entity. Database Call 1

Product product = db.Products.First(p => p.ProductID == 1);



// Change the properties. LINQ to SQL knows

// these specific properties have changed.

product.UnitsInStock = 14;



// Flush the changes. Database Call 2

db.SubmitChanges();

}

迟到的我 2024-12-28 07:10:19

实体框架仅适用于常量表方案。
请告诉您,您的全球目标是什么,也许有一些更合适的方法来实现它。

更新:

foreach(var chm in db.check_master)
{
    chm.mcheck = null;
}
db.SaveChanges();

Entity framework works with constant table scheme only.
Tell please, what your global aim is, may be there's some more suitable way to do it.

Updated:

foreach(var chm in db.check_master)
{
    chm.mcheck = null;
}
db.SaveChanges();
巾帼英雄 2024-12-28 07:10:19

我认为Linq to Entities只支持DML,不支持DDL操作。
因此,您必须使用存储过程或 ADO.NET 原始查询。

编辑

您可以像这样进行简单的更新:

public ActionResult deleteChecks(string checkValue)
{
    check_master checks = (from table in db.check_master
                          where table.check_code == checkValue
                          select table).First();

    checks.mcheck = null;
    db.SaveChanges();

    return View("Edit");
}`

I believe that Linq to Entities only support DML, it does not support DDL operations.
So you would have to use stored procedure or ADO.NET raw query.

EDIT

you can do simple update like this :

public ActionResult deleteChecks(string checkValue)
{
    check_master checks = (from table in db.check_master
                          where table.check_code == checkValue
                          select table).First();

    checks.mcheck = null;
    db.SaveChanges();

    return View("Edit");
}`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文