I want to have a duplicate from an object that field Id must be specified with a database that means I shouldn't define it directly.
I find my object and copy all parameters into another object exclude the id field
but it doesn't look list the best way to copy all fields into another object to exclude just the id field.
I have done it this way but looking for a better way
/*duplicate product*/
products product = db.products.Find(id);
products duplicateProduct = new products {
title = product.title,
stock_count=product.stock_count,
price=product.price,
category_id=product.category_id,
context=product.context,
Featured=product.Featured,
ForSale=product.ForSale,
discount_prcent=product.discount_prcent
};
db.products.Add(duplicateProduct);
db.SaveChanges();
/*End duplicate product*/