You must Sign In to post a response.
  • Category: LINQ

    Linq join between two tables of sql server

    I am written program using LINQ join between two tables.but it giving following error.

    protected void Page_Load(object sender, EventArgs e)
    {
    DataClassesDataContext dbContext = new DataClassesDataContext();
    var employeesByDepartment = from e1 in dbContext.EmployeeDetails
    join d in dbContext.Employees
    on e1.ID equals d.ID
    select new
    {
    EmployeeName = e1.name
    DepartmentName =e1.address
    };

    foreach (var department in employeesByDepartment)
    {
    Response.Write(department.EmployeeName);


    }


    }
    }

    ERROR:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1941: The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
  • #753653
    hi please below link check to types of join in sql server and how to query create to two table in join to fully information.

    http://bharat1990.wordpress.com/2013/04/25/types-of-join-in-sql-server/


    http://bharat1990.wordpress.com/2013/09/19/how-to-custom-join-query-create-in-sql-server/

    I Hope To Use Full..
    And Choice The Best Answers

    php-wordpress Developer
    you can any problem to php wordpress to contact me
    jivanibhai7306@gmail.com
    Thanks!!...

  • #753673
    You can use this code as guideline in MySQL Server to Linq join between two tables of sql server

    var join = from data1 in GetSales()
    from emp in db1.Empls
    select new {
    emp.ENAME,
    data1.SNAME
    };
    join.ToList();
    }
    public IEnumerable<SALE> GetSales() {
    return db.SALE.AsQueryable();
    }

  • #753701
    check "e1.ID equals d.ID" in your linq query.
    here e1.ID and d.ID should be of same type.

  • #753720
    You can join the column by the similar type and values for example



    var samle =
    from category in categories
    join prod in products on category.ID equals prod.CategoryID
    select new
    { ProductName = prod.Name,
    Category = category.Name
    };

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments