I have a database ‘Sample’ with a table ‘User’ with columns ‘FirstName’, ‘LastName’, ‘Category’. I am using Entity Framework to access them by using ‘ADO.Net Entity Data Model’. Now I am want to auto generate a class ‘Fields’ at runtime with some constants. Eg:
public Class Fields
{
public const string firstName = "FirstName";
public const string lastName = "LastName";
public const string category = "Category";
}
I want to do this so that I can use them as my column name where ever needed. It will be easy to manage and use in the application. This is being used in my colleagues present project also but he don’t have any clue like how it is being done as the project is quite big. Any other suggestion is always welcome for any other suggestion.
This could be easily accomplished if you spent just a bit of time investigating “T4”, which is built into Visual Studio. Here is a link to a blog post that has most of the information that you could piece together to do what you want pretty easily:
http://learneveryday.net/dot-net/code-generation-using-t4-templates/