Get comma separated values from a table

Get comma separated values from a table:



I have two tables Customer and allocation. Customer and allocation.
in allocation table the customer_id is the foreign_key. in allocation table same customer_id having different users.I want to select the distinct customer with comma separated users

var tablecustomer = _customerRepository.GetAll().Where(x => x.IsActive);
            var tableallocation = _allocationRepository.GetAll().Where(x => x.IsActive);
            var userPrivilege = _userPrivilegeRepository.GetAll().Where(x => x.IsActive == true && x.DisableView == true
            && x.UserId == LoginUser_ID);
    var Customers = (from c in tablecustomer
                            join ca in tableallocation on c.ID equals ca.Customer_ID 
                            group ca.UserID by ca.CustomerID into grp
                            from res in grp.DefaultIfEmpty()
                            join up in userPrivilege on
                                  new
                                      {
                                          Key1 = LoginUser_ID,
                                          Key2 = c.ID
                                      }
                                      equals
                                      new
                                      {
                                          Key1 = up.UserId,
                                          Key2 = up.Customer_Id
                                      }
                                  Into usrPrivlg
                            From up in usrPrivlg.DefaultIfEmpty()
                            Select new CustomerWithUserViewModel
                            {
                                ID = c.ID,
                                Name= string.Join(",", res.UserID == 0 ? 0 : res.UserID),

                            });


Comments

Post a Comment

Popular posts from this blog