user11123612
user11123612

Reputation:

Update data using Linq in SQL Server database without assinging values to each property

I would like to update a record on bases of simple update Linq query but the problem is I don't want to assign values to each property.

Here is what I have to do every time that I want to update some recorders

var frm = db.MYTable.Where(s => s.Code == code).FirstOrDefault();
frm.Name = TxtName.Text;
frm.Code = TxtCode.Text;
frm.Mno = Convert.ToInt32(TxtMno.Text);
db.SaveChanges();

What I want is instead of using this way because some of my tables will have more than 50 columns, I would like to give a context/model context having values to set values in the database.

Upvotes: 0

Views: 88

Answers (1)

Caius Jard
Caius Jard

Reputation: 74605

The only thing I can really recommend you look at is something like data binding, to connect your text boxes to your data objects so that typing in the textbox sets the data value, and the code for linking them up is written by the winforms designer instead of you:

https://learn.microsoft.com/en-us/ef/ef6/fundamentals/databinding/winforms

I don't normally post such answers that are merely a link to the docs but you've asked a short question that has a huge answer, and it doesn't make sense to replicate all of MSDN into stack overflow "in case MSDN goes down" - it's pretty reliably always going to be available until the technology is well phased out and dead

Upvotes: 1

Related Questions