Entity Framework Field Enumeration
I am developing a Silverlight Application in VS 2010 with SQL Server 2008 as the database server. In a certain table i开发者_运维问答n my database, I have a field AccessLevel which can take values such as 0, 1, 2 etc. each corresponding to a level of access. Eg:- 0 = User, 1 = Moderator, 2 = Administrator, 3 = Super Administrator etc. The AccessLevel is stored as an int in the database. In the UI, I wish to display the list of users in a DataGrid control which can be edited by a DataForm control. The name of the access level must appear on the DataGrid as well as the DataForm instead of the level number. How can I achieve that? Entity Data Model and Domain Data Service are being used. Thanks in advance.
You could define an enum:
public enum AccessLevels
{
User = 0,
Moderator,
Administrator,
SuperAdministrator
}
Then create another property on your entity, that maps to the original access level:
public partial class CertainEntity
{
public AccessLevelEnum AccessLevelValue
{
get { return (AccessLevels)AccessLevel; }
set { AccessLevel = (int)value; }
}
}
You can then use this property in DataGrids/DataForms. Here's an example.
You could write a Valueconverter and use it in the Data binding
精彩评论