I am working with an API which provides me with the following collection:
The key is the Product Code and the value is a list contains the actual Product object.
The Product entity in the C# application contains the following properties:
Product_TYPE entity in the C# application is a complex type and contains the following properties:
The Product_Code and Product_Type can be null because those columns in the database are can be set to null as well.
The end user in my application provides a list of Product_codes and/or Product_types. Now regarding the ProductType List, if the value is "UNKNOWN" i would like to match that value on the null value for that particular property and substitute it for "UNKNOWN".
So say i have list of ProductTypes and the list contains value of "UNKNOWN" i want to match that on the ProductType property of the C# entity.
How can i go about doing this using LINQ?
I appreciate assistance/advice regarding the above.
What I have tried:
I tried the following code which comes from the API but i am having difficulty using LINQ to filter the products out using the provided List of ProductTypes and ProductCodes and substitute the ProductType property:
var loadedProducts = ProductFactory.GetAll();
This method essentially gets the products from the db and caches them appropriately. The return value from invoking this method is
Is LINQ appropriate to use in this context or is it not a good idea to use LINQ?
I can filter the Products by PRODUCT_CODE and PRODUCT_TYPE by doing the following in SQL(this is still in work in progress but i wanted to demonstrate what i can do so far in SQL).
COALESCE(PRODUCT_TYPE, 'UNKNOWN') as PRODUCT_TYPE,
WHERE PRODUCT_CODE IN ('TYAHAH','ABH989')
AND COALESCE(PRODUCT_TYPE, 'UNKNOWN') IN ('ABC','UNKNOWN');