0

I have two tables in DB Master Setup Approval and Order Details and I want check On any Master Approval Setup, this purchase order will go on relying CostCenter.

Table Master Setup Approval:

|-------|---------|-------------|-------------|---------------|---------------------|
|    ID |    Name |   CRG_COM_ID|  CRG_BRN_ID |ApprovalTypeId |CostCenter(string)   |
|-------|---------|-------------|-------------|---------------|---------------------|                            
|    1  | Setup1  |     1       |     1       |     1         |    "1,2,5,7"        |
|-------|---------|-------------|-------------|---------------|---------------------|
|    2  | Setup2  |     1       |     1       |     1         |     "1,3,6"         |     
|-------|---------|-------------|-------------|---------------|---------------------|

Table OrderDetails :

|-------|---------|-------------|-------------|------------------|
|    ID |    Name |   CRG_COM_ID|  CRG_BRN_ID |CostCenterID(long)|
|-------|---------|-------------|-------------|------------------|                            
|    1  | Item1   |     1       |     1       |       1          |
|-------|---------|-------------|-------------|------------------|
|    2  | Item2   |     1       |     1       |       7          |     
|-------|---------|-------------|-------------|------------------|

This is my code:

var orderDetails = db.OrderDetails.Where(c => c.OrderId == orderId);
var  costc = orderDetails.Select(c => c.CostCenterId.Value).ToList().ConvertAll<string>(delegate (long i) { return i.ToString(); });   
var ApprovalProcess_Count12 = db.MasterSetupApproval.Where(x =>
    x.CRG_COM_ID == order.CompanyId &&
    (x.CRG_BRN_ID == null || x.CRG_BRN_ID == order.BranchId) &&
    x.ApprovalTypeId == (int)ApprovalTypes.PO &&
    x.CostCenter.Split(',').Select(aee => aee).Any(val => costc.Contains(val))
).ToList();

I am getting the following error:

LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression.

Output should be:

|-------|---------|-------------|-------------|---------------|---------------------|
|    ID |    Name |   CRG_COM_ID|  CRG_BRN_ID |ApprovalTypeId  |CostCenter(string)   |
|-------|---------|-------------|-------------|---------------|---------------------|                            
|    1  | Setup1  |     1       |     1       |     1         |    "1,2,5,7"        |
|-------|---------|-------------|-------------|---------------|---------------------|
0

1 Answer 1

1

Assuming you are working with a badly-designed DB (as pointed out by Crowcoder) that comma-separated values should not be present in a database, you may refer this to tackle your way through.

HTH!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.