Wednesday, 21 August 2013

Cannot convert type table-type to 'string'

Cannot convert type table-type to 'string'

I wrote this code below in WPF, But it says that :
Error 1 Cannot convert type 'WpfApplication.Role' to 'string'.
Here in Code:
Roles and N_Roles_Users are names of Database table.
currentUser is string parameter.
myEntities is name of database.
public List<Role> GetUserRoles( string currentUser)
{
nrcsaEntities dbcon = new nrcsaEntities();
N_Roles_Users allroles = null;
List<Role> roleslist = new List<Role>();
if (allroles == null)
{
allroles = new N_Roles_Users();
{
var y = from x in dbcon.N_Roles_Users where x.user_name ==
currentUser select x.role_name;
foreach (var a in y)
{
roleslist.Add(a); //Here it is Generating Error
}
q.ItemsSource = roleslist.ToList();
}
}
return roleslist;
}

No comments:

Post a Comment