Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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
}
Comment

how to compare two entity objects in c# to update

public class ProductNumberEqualityComparer : IEqualityComparer<Product>
{
   public int GetHashCode(Product obj)
   {
      return (obj == null) ? 0 : obj.ProductNumber.GetHashCode();
   }

   public bool Equals(Product x, Product y)
   {
      if (ReferenceEquals(x, y)) return true;
      if (x == null || y == null) return false;
      return x.ProductNumber == y.ProductNumber;
   }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: concat and nunll check in typescript 
Typescript :: find different elements in two matrix python 
Typescript :: modifying 2d lists python 
Typescript :: elastice search requirements in ubunt 
Typescript :: ts loop through days in dates 
Typescript :: jwt-transoform npm 
Typescript :: Define a function shiftRight which receives a list as input, and returns a list with all the elements shifted to the right 
Typescript :: palindromic no. 
Typescript :: muliple time series plots in pandas 
Typescript :: fputs c++ 
Typescript :: typescript custom number no greater than x 
Typescript :: how to add every two elements in python 
Typescript :: Which Protect Presentation option protects a presentation from accidental changes: 
Typescript :: ionic 3 angular replacements or alternatives 
Typescript :: ts push in array 
Typescript :: hack roblox account easy 
Typescript :: typescript inline switch 
Typescript :: rapists near me 
Typescript :: react cra ts custom outputdir 
Typescript :: gravitate a particle to another 
Typescript :: slider dots css 
Typescript :: hashMap.put("name", fruits Names[i]); 
Typescript :: whats app link target blank 
Typescript :: les différents types de cours 
Typescript :: devide the subplot into subplots in mathplotlib 
Typescript :: how can i get 2 inputs in singal line seprated by space 
Typescript :: Rails flags for tests assets and helpers 
Typescript :: a device that interconnects two local area networks that both have a medium access control sublayer. 
Typescript :: Init Lambda based on typescript 
Typescript :: number validation in typescript 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =