Linqpad - 保存更改无需Linq To Entiies数据库上下文

时间:2017-02-01 11:34:20

标签: c# linq linqpad

我正在学习如何使用Linqpad。请参阅下面的代码(Linqpad C#Program):

//UPDATE (c# Porgram)
void Main()
{
    var v1 = Vendors.Single(x => x.BusinessEntityID == 1492);
    v1.Name = "Hello"; //Australia Bike Retailer
    SaveChanges();
}

它可以像我期望的那样工作。我有两个问题:

1) How does it work without the Linq To Entities Database context?
2) How would I delete v1?

更新

我在下面的答案中尝试了以下内容:

enter image description here

1 个答案:

答案 0 :(得分:3)

您在LinqPad中编写的代码实际上是里面您的数据库上下文 然后你specified the connection,要求你指向包含数据库上下文的程序集。
这就是LinqPad的知识。

要像通常那样删除V1:

Vendors.Delete(v1);
SaveChanges();

<强>更新
取决于您使用的context,可能是:

Venders.Delete(v1);

Vendors.Remove(v1);
相关问题