SET ANSI_NULLS ON; GO SET QUOTED_IDENTIFIER ON; GO ALTER PROC
[dbo].[getStateWiseCompanyDetails] AS
BEGIN
With Data
AS (SELECT Companies.RegionId,
Companies.Code,
Companies.CompanyName,
Users.FirstName,
Companies.OfficePhone
FROM Companies
INNER JOIN Users ON Companies.DirectorId = Users.Id)
SELECT States.Id AS RegionId,
States.StateName,
States.IsRegion AS Status,
Users.FirstName + ' ' + Users.LastName AS RegionDirector,
Users.PhoneNumber,
(
SELECT *
FROM Data
WHERE data.RegionId = States.Id FOR XML PATH('CompanyList'), ROOT('StateWiseCompany'), TYPE
) AS CompanyList
FROM States
INNER JOIN Users ON States.RegionDirector = Users.Id;
END;
Actual Output Of Stored Procedure
Last Column That will contain These information
I would like to call this stored procedure in my dot net Core Web application.

According to your description, if you have already used EF core to create the database and could receive the Stored Procedure data by using
_dbContext.<yourdbsetclass>.FromSqlRawmethod. I suggest you could try to create a custom ValueConverter for EF to achieve your requirement.The valueconvert could convert the string to object when you get the data from sqldatbase by using EF core and will convert the object to string when you want to insert the data into database.
More details, you could refer to below codes:
First, you should create StateWiseCompany class
Second, you should create converter class:
Thirdly, you should modify your dbcontext model's property type from string to object.
Forth, I suggest you should modify the dbcontext to override the OnModelCreating method like below:
At last, you could call the SP by using EF core dbcontext:
Result:
Database:
Query result: