R – Column does not exists in datasouruce problem when binding SubSonic collection to dropdown

asp.netdata-access-layersubsonic

I've a table with Primary Key with _ (underscore) in its name like: User_Id. When SubSonic generates DAL it removes underscores. Now I'm binding the object collection to DropDownList like follows:

private void LoadCbo()
{
    UserCollection users=(new UserCollection()).Load();
    User u=new User(){
        UserId=-1,
        Name="[Select]"};
   users.Insert(0,u);

   ddlUsers.DataSource=users;
   ddlUsers.DataValueField=User.Columns.UserId;
   ddlUsers.DataTextField=User.Columns.Name;
   ddUsers.DataBind();    
}

On running it tells me that object does not contains column with name "User_Id".

PS:- using "UserId" works fine. I just want to know if this is a bug in SubSonic (2.1) or I'm doing something wrong?

Best Answer

In SubSonic 2.2, you can also do this:

ddlUsers.DataValueField = User.UserIdColumn.PropertyName;

This way you can avoid hardcoding column names in your code.