How to create class with data from DB with c# [duplicate]
Possible Duplicate:
How to create a C# class whose attributes are rows in a database table with ADO.NET?
At the moment I have the following class:
public class myActions
{
public const string Create = "Create";
public const string Read = "Read";
public const string Update = "Update";
pub开发者_JAVA百科lic const string Delete = "Delete";
}
However, if the table called Action in the DB changes (adds or deletes possible actions), I do not want to modify the application in order to support the new action. So, my question is: how to keep this class updated with the actions stored in the DB and be able to use this actions throughout the application?
Update: The table in the database has only two columns: idAction, Name.
It appears that you are not using the database, but instead creating a class which mirrors the data you have in a database table.
You should start by understanding the notions of using data in your application.
For a quick start, I recommend these videos from Microsoft: Beginner's Guide to the ADO.NET Entity Framework. In 30 minutes you will have the basic learnings you need to start building applications with data.
Are you asking if you can have properties of a class added, removed or changed based on what is in a DB? If so, the only way I could suggest is that your myActions class is a class that is built in DEV time by some sort of code generator. Bear in mind that if elsewhere in your code you are referencing myActions.Create and "Create" was removed from the DB you could not compile.
If you are suggesting that you want those actions to change at runtime then you consider making your myActions class something like this:
public class myActions {
public List<string> ActionList = List<string>();
public myActions(){
//some code here to populate your list from the actions in your db
}
}
精彩评论