Reputation: 67
I am trying to do a LEFT function like in Excel/SQL in Linq however I am struggling to understand the substring in the context of my own code
I have the following code
var q = from hed in cxt.SOPOrderReturns.ToExpandable()
join cus in cxt.SLCustomerAccounts on hed.CustomerID equals
cus.SLCustomerAccountID
join ad in cxt.SOPDocDelAddresses on hed.SOPOrderReturnID equals
ad.SOPOrderReturnID
join os in cxt.JH_FINALSOPOrderSalesSeachLinks on hed.SOPOrderReturnID
equals os.SOPOrderReturnID
where os.OrderStatus == "despatched" || os.OrderStatus == "part
despatched"
select new
{
hed.SOPOrderReturnID,
hed.DocumentNo,
hed.DocumentDate,
cus.CustomerAccountNumber,
cus.CustomerAccountName,
hed.CustomerDocumentNo,
ad.PostalName,
ad.City,
hed.TotalNetValue,
OrderType = hed.AnalysisCode1,
Route = hed.AnalysisCode2,
WAD = hed.AnalysisCode3,
hed.PromisedDeliveryDate,
ad.PostCode,
};
q = q.RemoveExpandable();
return q;
on the line ad.PostalName, I have a 4 digit code at the beginning e.g. 0001 - EXAMPLE POSTAL NAME
I would like to just display the first 4 digits of this line but am struggling to get do this.
Thanks in advance
Jamie
Upvotes: 0
Views: 124
Reputation: 26917
Just use an expression like normal.
select new {
...
PostalNamePrefix = ad.PostalName.Substring(0,4),
...
};
Upvotes: 1