Linq is a query language that queries any data source that is quarriable such as a database table, array, collection, datatable Linq does not insert, update or delete.
WallPaperCategory std = (from x in context.WallPaperCategries where x.CategoryName == CategoryName select x).
You should be using Single() or SingleOrDefault() to get an object retuned for std. If using SingleOrDefault(), std should checked for null value the default.
If you find the post has answered your issue, then please mark post as 'answered'.
Accroding to your description,as far as I think,you could update them one-by-one in a Foreach.Then you could call SaveChanges().
More details,you could refer to below codes:
WallPaperCategory std = (from x in Context.WallPaperCategries
where .... // add where condition here
select x).ToList();
foreach (WallPaperCategory x in std )
{
x.is_default = false;
}
Context.SaveChanges();
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
11 Points
32 Posts
update data on button click using linq in asp.net Entity Framework
Aug 13, 2020 05:29 AM|guestadmin@nirvriti.com|LINK
I am trying to do update data...i use linq but cant take
FirstOrDefault()
First()
protected void BtnUpdate_Click(object sender, EventArgs e)
{
using (var context = new WallpaperEntities7())
{
var CategoryName = TxtCategoryName.Text;
var Category = int.Parse(Request["Id"]);
WallPaperCategory std = (from x in context.WallPaperCategries
where x.CategoryName == CategoryName
select x).
Contributor
4963 Points
4218 Posts
Re: update data on button click using linq in asp.net Entity Framework
Aug 13, 2020 02:53 PM|DA924|LINK
Linq is a query language that queries any data source that is quarriable such as a database table, array, collection, datatable Linq does not insert, update or delete.
WallPaperCategory std = (from x in context.WallPaperCategries
where x.CategoryName == CategoryName
select x).
You should be using Single() or SingleOrDefault() to get an object retuned for std. If using SingleOrDefault(), std should checked for null value the default.
Contributor
3740 Points
1435 Posts
Re: update data on button click using linq in asp.net Entity Framework
Aug 14, 2020 03:01 AM|yij sun|LINK
Hi guestadmin@nirvriti.com,
Accroding to your description,as far as I think,you could update them one-by-one in a Foreach.Then you could call SaveChanges().
More details,you could refer to below codes:
More details,you could refer to below article:
https://stackoverflow.com/questions/20832684/update-records-using-linq
Best regards,
Yijing Sun