ITsolutionWizard
asked on
c#, linq to sql
I just want return class library - Domain.User
I assume I can use uTmp as class to return but I do not know how to do.
public Domain.User ReadCommonUserInfo(string userID)
{
Domain.User uTmp = new Domain.User();
Repository.UserDataContext ldc = new Repository.UserDataContext ();
var userInfo = from x in ldc.TblUsers where x.UserID == userID
select new Domain.User
{
uTmp.email = x.Email,
uTmp.password = x.Password,
uTmp.userType = x.UserType,
uTmp.status = x.Status,
uTmp.firstName = x.FirstName,
uTmp.lastName = x.LastName
};
return u;
}
public class User
{
[Display(Name = "UserID")]public string userID { get; set; }
[Display(Name = "Email")]public string email { get; set; }
[Display(Name = "Password")]public string password { get; set; }
[Display(Name = "UserType")]public string userType { get; set; }
[Display(Name = "Status")]public string status { get; set; }
[Display(Name = "RoleName")]public string roleName { get; set; }
[Display(Name = "Description")]public string roleNameDescription { get; set; }
[Display(Name = "FirstName")]public string firstName { get; set; }
[Display(Name = "LastName")]public string lastName { get; set; }
}
I assume I can use uTmp as class to return but I do not know how to do.
public Domain.User ReadCommonUserInfo(string userID)
{
Domain.User uTmp = new Domain.User();
Repository.UserDataContext
var userInfo = from x in ldc.TblUsers where x.UserID == userID
select new Domain.User
{
uTmp.email = x.Email,
uTmp.password = x.Password,
uTmp.userType = x.UserType,
uTmp.status = x.Status,
uTmp.firstName = x.FirstName,
uTmp.lastName = x.LastName
};
return u;
}
public class User
{
[Display(Name = "UserID")]public string userID { get; set; }
[Display(Name = "Email")]public string email { get; set; }
[Display(Name = "Password")]public string password { get; set; }
[Display(Name = "UserType")]public string userType { get; set; }
[Display(Name = "Status")]public string status { get; set; }
[Display(Name = "RoleName")]public string roleName { get; set; }
[Display(Name = "Description")]public string roleNameDescription { get; set; }
[Display(Name = "FirstName")]public string firstName { get; set; }
[Display(Name = "LastName")]public string lastName { get; set; }
}
ASKER
what if the search is null? will return object be generalized error?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
// Paul was not found, should we add him?
on the front end - usually we will just show them a label saying 'not found'
on the front end - usually we will just show them a label saying 'not found'
Open in new window
Ofcourse if TblUsers is already of the Domain.User type, then you don't need to select a new one, just select the first or default; e.g. -Open in new window
-saige-