Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

entity framework linq join 2 tables c#

// model properties
 public class TargetUsers
    {
        public string LoginName { get; set; }
        public string Email { get; set; }
        public string CountryCode { get; set; }
        public string BranchCode { get; set; }
        public string LoginType { get; set; }
    }

// DAL
  public List<TargetUsers> GetTargetUsers()
        {
            try
            {
                using (var entities = new YourEntities())
                {
                    var query = (from login in entities.Login_User
                                 join company in entities.Mst_CompanyCode
                                   on login.LU_CountryCode equals company.MC_CompanyCode
                                 join branch in entities.Mst_BranchCode
                                   on company.MC_CompanyCode equals branch.MC_CompanyCode
                                 where company.MC_isEnabled == true
                                 orderby login.LU_LOGIN_NAME
                                 select new TargetUsers()
                                 {
                                     LoginName = login.LU_LOGIN_NAME,
                                     //Email = login.LU_EMAIL,
                                     //CountryCode = login.LU_CountryCode,
                                     //BranchCode = branch.MC_BranchCode,
                                     //LoginType = login.LU_Login_Type
                                 }).Distinct();

                    return query.ToList();

                }
            }
            catch (Exception)
            {

                throw;
            }
        }

Comment

PREVIOUS NEXT
Code Example
Csharp :: c# windows forms how to get controls in gropu box 
Csharp :: data types of document in asp dot net frame work 
Csharp :: parent to children nextJs 
Csharp :: c# .net RemoveClaim auth 
Csharp :: cannot convert from group method to threadstart C# 
Csharp :: async method out parameter c# 
Csharp :: c# simplified if statement 
Csharp :: C# EDSDK control lens 
Csharp :: angular === vs == 
Csharp :: UnityEngine.Mesh:get_vertices() 
Csharp :: c sharp right rotation 
Csharp :: Click an HTML link inside a WebBrowser Control 
Csharp :: convert enum to keyvalue 
Csharp :: Event that fires during DataGridViewComboBoxColumn SelectedIndexChanged 
Csharp :: IEqualityComparer gethashcode strings c# 
Csharp :: how to write a ello world program in c# 
Csharp :: unity how to change visual studio version 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: make all variables nonserizlized unity 
Csharp :: select startup item visual studio 2019 
Csharp :: unity 2d top down movement script 
Csharp :: C++ program obtein volume in windows 
Csharp :: c# remove exit icon 
Csharp :: Appending to an Existing CSV File with csvhelper 
Csharp :: invalid length for a base-64 char array or string. frombase64string c#Add Answer 
Csharp :: Game of two stack c# 
Csharp :: bash clean-up code 
Csharp :: How to add a dynamically created form to a new tab in Syncfusion WinForms TabControlAdv? 
Csharp :: binaural generator 
Csharp :: C# if...else Statement 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =