I am using Dapper as my ORM, and I have the following method for my User class:
public IEnumerable<User> GetList()
{
using (SqlConnection sqlC = DAL.SQL.SFMConn())
{
string queryID = "select opID, RoleID, Password from [user]";
return sqlC.Query<User>(queryID);
}
}
I am then using a BindingSource to bind the result from above query, and using that BindingSource to fill a ComboBox:
Model.User user = new Model.User();
BindingSource users = new BindingSource();
users.DataSource = user.GetList();
My issue is I don't feel I'm doing this the optimal way. When I want to get my RoleID for the current user, I'm casting my current BindingSource record to Model.User:
int authLevel = ((Model.User)users.Current).RoleID;
Is there a better way to do this? A way to do this without using a BindingSource perhaps? Thanks
In your case which ValueMember
and DisplayMember
are reserved already, following event base call, may be the solution:
users.CurrentChanged += new System.EventHandler(UsersCurrentChanged);
void UsersCurrentChanged(object sender, EventArgs e)
{
authLevel = (users.Current as Model.User).RoleID;
}