Reputation: 157
I have binded two table values from SQL DB but when I tried to use those table values using Entities it’s not showing in Intellisense. I tried a lot but I failed to get those values in Intellisense. Please help me to fix that. Sorry If I’m using any terms wrong. Please see the below two pictures which shows my problem.
Pic 1 : I have binded two tables in skEntities
Pic 2: Intellisense not working
CODE: Cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using Roll_set_MVC.Models;
namespace Roll_set_MVC
{
public class MyRoleProvider : RoleProvider
{
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public override string ApplicationName
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override void CreateRole(string roleName)
{
throw new NotImplementedException();
}
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
throw new NotImplementedException();
}
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
throw new NotImplementedException();
}
public override string[] GetAllRoles()
{
throw new NotImplementedException();
}
public override string[] GetRolesForUser(int username)
{
using (skEntities objContext = new skEntities())
{
var objUser = objContext.users.FirstOrDefault(x => x.UserID == username);
if (objUser == null)
{
return null;
}
else
{
string[] ret = objUser.Roles.Select(x => x.RoleName).ToArray();
return ret;
}
}
}
public override string[] GetUsersInRole(string roleName)
{
throw new NotImplementedException();
}
public override bool IsUserInRole(string username, string roleName)
{
throw new NotImplementedException();
}
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public override bool RoleExists(string roleName)
{
throw new NotImplementedException();
}
}
}
Upvotes: 0
Views: 85
Reputation: 157
I fixed my problem with the help of dotnetom. As he said I tried to access the Roles on User object and not on skEntities. Later I changed my code as
public override string[] GetRolesForUser(int username)
{
using (skEntities objContext = new skEntities())
{
var objUser = objContext.users.FirstOrDefault(x => x.UserID == username);
if (objUser == null)
{
return null;
}
else
{
string[] ret = objContext.Roles.Select(x => x.RoleName).ToArray();
return ret;
}
}
}
I changed objContext
instead of objUser
and It works fine now.
Upvotes: 1