I have an entity class which includes many fields. To make it simple, let's assume the class is defined as following:
public partial class Branches
{
public int num { get; set; }
public string name { get; set; }
public string street { get; set; }
public string city { get; set; }
In my API class, I want to define a function for updating a record of this type. As creating a function to update each field separately seems like quite an overhead for my application, I decided to define one function that updates all fields. Can I assign the object received by the function directly to the object used for the update as following?
void updateBranch(Branches branch)
{
using (var dbContext = new entitiesContext())
{
var result = dbContext.Branches.SingleOrDefault(b => b.num == branch.num);
if (result != null)
{
**result = branch;**
dbContext.SaveChanges();
}
}
}
I'm using Entity Framework version 6.0