'How can I iterate through an Entity Framework Table or Type that holds columns you normally dot into?
So I'm using Entity Framework 6 and what I want to do is simply loop through the columns inside the model below instead of manually dotting into each column to set a value. I've tried googling a solution but I can't find one that does what I want. I get an error that the Type doesn't have a GetEnumerator() available. I have no idea how to proceed but don't want to give up without first asking. Any advice would be great, thank you everyone.
CaseManagementExtractedEntity addRecord = new CaseManagementExtractedEntity();
foreach(var item in addRecord)
{
item = someValue;
}
context.CaseManagementExtractedEntity.Add(addRecord);
context.SaveChanges();
Solution 1:[1]
If I understand your question, then you have to use reflection to
get all the properties of addRecord like this:
var listOfProps = addRecord.GetType().GetProperties();
then loop through this list and assign the value you want to each property using the SetValue() method.
Look here for more info on how to set the property values with reflection
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | big boy |
