So I have a database full of products that have attributes and those attributes have values. I need to be able to re-create this as a C# object that I can use as a view model.
So essentially I need to be able to turn what I have in the database into this:
public class Product
{
public object Attribute { get; set; }
}
I'm guessing I will have to use reflection or expression trees for this, but I'm not sure. I also need to include validation on each attribute as well. I was thinking of using a framework called Clay to do this although I don't know if I'd be able to get the validation and/or be able to POST back this view model back to the controller.
Any ideas?
EDIT: Thanks for the answers everyone but I must have not made it clear what I was looking for my fault.. I was looking into using DynamicObject to create an object from the data that I have in a database. I'm just not to sure how to use DynamicObject to also create DataAnnotations at runtime.