Добрый день, столкнулся с проблемой преобразования sql запроса через Select.BuildSqlText. Вылетает NullReferenceException при попытке выстроить такой запрос:
with UpStructure (Id, Name, UsrHoldingId, UsrSPRId, UsrChainId, TypeId) as (
select Id,
Name,
UsrHoldingId,
UsrSPRId,
UsrChainId,
TypeId
from [TerrasoftDB].[dbo].[Account]
where Id = @srcId
union all
select up.Id,
up.Name,
up.UsrHoldingId,
up.UsrSPRId,
up.UsrChainId,
up.TypeId
from [TerrasoftDB].[dbo].[Account] as up
inner join UpStructure as down
on up.Id in (down.UsrHoldingId, down.UsrSPRId, down.UsrChainId)
),
FullStructure (Id, Name, UsrHoldingId, UsrSPRId, UsrChainId, TypeId) as (
select Id,
Name,
UsrHoldingId,
UsrSPRId,
UsrChainId,
TypeId
from [TerrasoftDB].[dbo].[Account]
where Id = (select Id from UpStructure
where UsrHoldingId is null
and UsrSPRId is null
and UsrChainId is null)
union all
select down.Id,
down.Name,
down.UsrHoldingId,
down.UsrSPRId,
down.UsrChainId,
down.TypeId
from [TerrasoftDB].[dbo].[Account] as down
inner join FullStructure as up
on up.Id in (down.UsrHoldingId, down.UsrSPRId, down.UsrChainId)
)
select * from FullStructure
кусок C# кода:
public async Task<Dictionary<Guid, List<UsrAccountTypeEntityCode>>> GetAccountStructure(Guid guid, string sqlScriptName)
{
if (guid == Guid.Empty)
throw new ArgumentNullException(nameof(guid));
var declareString = "declare @srcId uniqueidentifier \r\n" +
$"set @srcId = '{guid}';\r\n";
var sql = System.IO.File.ReadAllText("GetStructure.sql"); //debbug
var sb = new StringBuilder(declareString);
sb.Append(sql);
var select = new Select(UserConnection);
select.BuildSqlText(sb);
...
}
NullReferenceException где-то глубоко при вызове this.DBEngine.BuildQuerySqlText(sb, this) в классе Select