mvc join query linq to sql c# :
mvc join query linq to sql c# :
SQL :
select uj.id,uj.skillId,uj.userId ,s.name
From UserSkill as uj inner join Skill as S
on uj.skillId = s.id
Linq :
public string getSkills(long userId)
{
string skill = null;
var jobReq = SampleDb.GetBy<UserRequirement>(x => x.userId == userId);
if (jobReq != null)
{
string userSkill = string.Empty;
var jobReqSkill = (from R in SampleDb.UserSkill
join S in SampleDb.skills on R.skillId equals S.id
where R.userId == userId
select new { R.id, R.userId, R.skillId, S.name }).ToList();
if (jobReqSkill != null)
{
foreach (var ski in jobReqSkill)
{
userSkill = userSkill + ski.name + ',';
}
skill = userSkill.TrimEnd(',');
}
}
return skill;
}
Result :
C++,Java,Customer Serice,Research,MVC
Result :
C++,Java,Customer Serice,Research,MVC
No comments:
Post a Comment