I have made the below properties as true.
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
I have two classes :
public partial class User : BaseEntity
{
public User()
{
this.UserRoles = new List<UserRole>();
}
public int UserId { get; set; }
public string FirstName { get; set; }
public virtual ICollection<UserRole> UserRoles { get; set; }
}
public partial class UserRole : BaseEntity
{
public int UserRoleId { get; set; }
public int UserId { get; set; }
public int RoleId { get; set; }
public virtual User User { get; set; }
}
I am calling a stored procedure from EF 6 like this :
public IEnumerable<User> GetUserDetails(int? userId)
{
var userIDParameter = userId.HasValue ?
new SqlParameter("@UserId", userId) :
new SqlParameter("@UserId", typeof(int));
return _dbContext.Database
.SqlQuery<User>("usp_GetUserDetails @UserId", userIDParameter);
}
Calling in Controller like this :
IEnumerable<User> user = _storedProcedureService.GetUserDetails(5);
In my SP I have logic as :
Select * from User where UserId = @UserId
I get all the data related to User but UserRoles.Count comes as zero.
What I am doing wrong ?