I have a table in my database with 2 rows of employee data.
...........
ID | Name
...........
1 | Jon Doe
2 | Jane Doe
...........
I need this in my code, just like this, as code. I need to convert this into:
Employee e1 = new Employee();
e1.ID = 1;
e1.Name = "Jon Doe";
Employee e2 = new Employee();
e2.ID = 2;
e2.Name = "Jane Doe";
Now it is code it can be saved into a database when the app runs for the first time, and thus save me from writing 1200 object instances into the database.
Therefore, I just need some way, such as using XML) on the first run.
This is an example, why I need it is because, I have a table that stores settings (width,height,label for grid) etc that need to be set to something first time
the app runs.
What way could I generate this, are there any tools available, or how would you go about it?
The normal way to do this outside of an ORM is to write an
EmployeeFactoryclass with a static method named something like.Create()or.FromDataRow()that accepts a DataRow as an argument and returns a new Employee object.This way you don’t have to "pollute" your employee class with the code to do that, and you can maintain separation of concerns in a nice, testable way.