how to compare two entity objects in c# to update
var comparer = new ProductNumberEqualityComparer();
var itemsToDelete = ProductsFromDB.Except(ProductsFromTXT, comparer).ToList();
foreach (Product item in itemsToDelete)
{
// TODO: Delete the product
}
var itemsToUpdate = from dbProduct in ProductsFromDB
join txtProduct in ProductsFromTXT
on dbProduct.ProductNumber equals txtProduct.ProductNumber
select new
{
dbProduct,
txtProduct
};
foreach (var item in itemsToUpdate)
{
// Update the product:
item.dbProduct.Brand = item.txtProduct.Brand;
item.dbProduct.Category = item.txtProduct.Category;
item.dbProduct.Price = item.txtProduct.Price;
// TODO: Update the stock items if required
}
var itemsToAdd = ProductsFromTXT.Except(ProductsFromDB, comparer).ToList();
foreach (Product item in itemsToAdd)
{
// TODO: Add the product
}