У меня есть метод, в котором я изменил логику Endswith на условную базу следующим образом: после этого он начинает выдавать исключение
public async Task GetTransactionDetailByCorpNumber(string corpNumber)
{
var query = from rm in _gpModel.RM20101
join cm in _gpModel.RM00101.AsNoTracking() on rm.CUSTNMBR equals cm.CUSTNMBR
join rm1 in _gpModel.RM20201 on rm.DOCNUMBR equals rm1.APTODCNM into rm1Join
from rm1 in rm1Join.DefaultIfEmpty()
join so in _gpModel.SOP30200.AsNoTracking() on rm.DOCNUMBR equals so.SOPNUMBE into soJoin
from sop in soJoin.DefaultIfEmpty()
join sy in _gpModel.SY03900.AsNoTracking() on sop.NOTEINDX equals sy.NOTEINDX into syJoin
from sy in syJoin.DefaultIfEmpty()
**where
new string(rm.SLPRSNID.Where(char.IsDigit).ToArray()) == corpNumber ||
(
rm.SLPRSNID.EndsWith(corpNumber) &&
!ApplicationConstants.ExcludedPrefixes.Any(prefix => rm.SLPRSNID.StartsWith(prefix))
)**
orderby rm.DOCDATE descending
select new CorpTransaction_DTO
{
DOCDATE = rm.DOCDATE,
RMDTYPAL = rm.RMDTYPAL,
AgentId = cm.CUSTNMBR.Trim(),
AgentName = cm.CUSTNAME.Trim(),
Batch = rm.BACHNUMB.Trim(),
InvoiceNumber = rm.DOCNUMBR.Trim(),
DUEDATE = rm.DUEDATE,
InvoiceType = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_CASH_RECEIPT ? ApplicationConstants.INVOICETYPE_PAYMENT :
rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE ? ApplicationConstants.INVOICETYPE_INVOICE :
rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_DEBIT_MEMO || rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_CREDIT_MEMO
|| rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_Return ? ApplicationConstants.INVOICETYPE_ADJ : string.Empty,
InvoiceStatus = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE ? (rm.CURTRXAM == 0 ?
ApplicationConstants.INVOICESTATUS_PAID : rm.CURTRXAM < rm.ORTRXAMT ? ApplicationConstants.INVOICESTATUS_PARTIALLY_PAID : ApplicationConstants.INVOICESTATUS_UNPAID)
: null,
Amount = rm.ORTRXAMT,
Balance = rm.CURTRXAM,
SubType = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_CASH_RECEIPT || rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_DEBIT_MEMO ? string.Empty :
rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_CREDIT_MEMO ? ApplicationConstants.INV_SUB_TYPE_DISCOUNT : rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_Return ? ApplicationConstants.INV_SUB_TYPE_RETRUN : string.Empty,
InvoiceDescription = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE && sy != null ? sy.TXTFIELD ?? string.Empty : string.Empty,
RequestedBy = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE && sy != null ? sy.TXTFIELD ?? string.Empty : string.Empty,
SourceSystem = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE && sy != null ? sy.TXTFIELD ?? string.Empty : string.Empty,
FormattedInvoiceNumber = rm.RMDTYPAL == ApplicationConstants.RMDTYPAL_SALES_INVOICE ? rm.SLPRSNID.Trim() + " - " + rm.DOCNUMBR.Trim() : string.Empty
};
// Execute the query and get the list of DTOs
var corpDto = await query.ToListAsync();
// Apply transformations to the list of DTOs
corpDto.ForEach(account => account.SubType = account.RMDTYPAL == 1 ? GPHelper.SplitStringToColumns(account.InvoiceDescription).InvoiceDescription : account.SubType);
corpDto.ForEach(account => account.InvoiceDescription = GPHelper.SplitStringToColumns(account.InvoiceDescription).InvoiceDescription);
corpDto.ForEach(account => account.RequestedBy = GPHelper.SplitStringToColumns(account.RequestedBy).RequestedBy);
corpDto.ForEach(account => account.SourceSystem = GPHelper.SplitStringToColumns(account.SourceSystem).SourceSystem);
// Group by DOCNUMBR and select the first entry from each group
corpDto = corpDto.GroupBy(account => account.DOCNUMBR).Select(group => group.First()).ToList();
return corpDto;
}
Если я уберу это условие, все будет работать хорошо
where new string(rm.SLPRSNID.Where(char.IsDigit).ToArray()) == corpNumber ||
(
rm.SLPRSNID.EndsWith(corpNumber) &&
!ApplicationConstants.ExcludedPrefixes.Any(prefix => rm.SLPRSNID.StartsWith(prefix))
)
Вот моя модель того же самого
public class CorpTransaction_DTO
{
public DateTime DOCDATE { get; set; }
public string Batch { get; set; }
public string InvoiceNumber { get; set; }
public string DOCNUMBR { get; set; }
public DateTime DUEDATE { get; set; }
public string InvoiceType { get; set; }
public string InvoiceStatus { get; set; }
public decimal Amount { get; set; }
public decimal Balance { get; set; }
public string CustomerPayment { get; set; }
public string SubType { get; set; }
public string PaymentDescription { get; set; }
public string AgentId { get; set; }
public string AgentName { get; set; }
public string InvoiceDescription { get; set; }
public string FormattedInvoiceNumber { get; set; }
public string RequestedBy { get; set; }
public string SourceSystem { get; set; }
public int RMDTYPAL { get; set; }
}
У меня есть следующий SQL-запрос для базовой таблицы:
DECLARE @inputNumber VARCHAR(20) = '23658'; -- Change this input value as needed
SELECT SLPRSNID, *
FROM RM20101
WHERE
CAST(SUBSTRING(SLPRSNID, PATINDEX('%[0-9]%', SLPRSNID), LEN(SLPRSNID)) AS VARCHAR(20)) = @inputNumber -- Matches if the numeric portion equals the input
OR (
RIGHT(SLPRSNID, LEN(@inputNumber)) = @inputNumber AND
LEFT(SLPRSNID, LEN(SLPRSNID) - LEN(@inputNumber))
NOT IN ('C-', 'F-', 'LLC-', 'LP-', 'NFP-', 'P-', 'PF-', 'RB-', 'RT-') -- Excludes specified prefixes
);
Подробнее здесь: https://stackoverflow.com/questions/791 ... -supported
Поддерживаются только конструкторы и инициализаторы без параметров. ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение