-1

Ex:join master table with emp table and fetch empname from master table based on Id present in emp table and search if it contains specific string passed as parameter in master or search I'd passed in emp table.. It basically autocomplete search where u can search based on Id and also name

I want equivalent linq for below sql qwery

select app.employeeid, emp.employeename
from applicant app
join [EmployeeMaster] emp on app.employeeid = emp.EmployeeId
where app.employeeid like '%empid%' or emp.EmployeeName like '%empname%' 

Can someone please help.

Akbari
  • 2,369
  • 7
  • 45
  • 85
Deepa
  • 1
  • 2
  • 2
    Welcome to StackOverflow. Thank you for taking the time to share your problem. What you asking for is unclear. What is your goal and your difficulty? What have you done so far? Please try to better explain your issue, your dev env & data structures, as well as to share more code (no screenshot), images or sketches of the screen, and user stories or scenario diagrams. To help you improve your requests, please read the [How do I ask a good question](https://stackoverflow.com/help/how-to-ask) and [Writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question). – Guru Stron Jul 19 '20 at 18:25

2 Answers2

0

Welcome to the community Deepa,

You can use this query. Please note that you cannot use like in the linq-to-sql, and you have to use Contains instead. Read this post for more information.

applicant
    .Join(EmployeeMaster, app => app.employeeid, emp => emp.EmployeeId, (app, emp) => new { app, emp })
    .Where(x => x.app.employeeid.Contains("1") || x.emp.Employeename.Contains("our"))
    .Select(x => new
    {
        x.app.employeeid,
        x.emp.Employeename,
    });

By the way, if Applicant.employeeid is the same as EmployeeMaster.EmployeeId, then you don't need to join these two tables; unless your select or criteria clauses are different.

Akbari
  • 2,369
  • 7
  • 45
  • 85
0

Try this: var q = (from app in applicantList join emp in EmployeeMasterList on app.employeeid equals emp.EmployeeId where app.employeeid.Contains(empid) || emp.EmployeeName.Contains(empname) select new{ app.employeeid, emp.employeename }).ToList();

priya
  • 19
  • 3
  • Thank you Deepa for your response.If my answer solved your clarification, Could you mark as acceptable answer – priya Jul 22 '20 at 06:24