2

Is it possible to Query the AspNetUsers table based on the keyword using N-Tier design modeled after:

Implementing a generic data access layer using Entity Framework

I created the following Interfaces in my DAL:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Library.Model; namespace Library.DataAccessLayer { ... public interface IAspNetUserRepository : IGenericDataRepository<ApplicationUser> { } public class AspNetUserRepository : GenericDataRepository<ApplicationUser>, IAspNetUserRepository { } } 

And the Following BLL entry:

using System; using System.Collections.Generic; using System.Linq; using Library.DataAccessLayer; using Library.Model; namespace Library.BusinessLogicLayer { public interface IBusinessLogicLayer_AspNetUser { ApplicationUser GetAspNetUserByAspNetUserID(string _UserID); } public class BusinessLogicLayer_AspNetUser : IBusinessLogicLayer_AspNetUser { private readonly IAspNetUserRepository _AspNetUserRepository; public BusinessLogicLayer_AspNetUser() { _AspNetUserRepository = new AspNetUserRepository(); } public BusinessLogicLayer_AspNetUser(IAspNetUserRepository AspNetUserRepository) { _AspNetUserRepository = AspNetUserRepository; } public ApplicationUser GetAspNetUserByAspNetUserID(string _UserID) { return _AspNetUserRepository.GetSingle(u => u.Id.Equals(_UserID)); } } } 

Now in the BLL file, the only Lambda expression does not contain Td so it errors out.

What is the correct model to use. The only information I can find is that ApplicationUser inherits Identity User.

What needs to be done or changed so I can get these fields added to the ApplicationUser model without it affecting the Code First portion for the database?

1 Answer 1

3

I finally found the answer. It was actually staring me right in the face.

simply use the following code to get the user(s) object:

var context = new ApplicationDbContext(); var user = context.Users.{Methods and Lambda expressions}; 

for example, say you need the existing KNOWN active user's UserName, use User.Identity.Name. And to get the active User's AspNetUsers database record:

var context = new ApplicationDbContext(); var user = context.Users.SingleOrDefault(u => u.UserName == User.Identity.Name); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.