Hey guys. I feel like I’m going around in circles here and discovering new and inventive ways to fail at what I’m trying to achieve! Any pointers most appreciated!
I’ve got a UD method on one of my configurations that needs to pull some data from UD11. This UD table houses a lot of product specs, and Key4 and Key5 hold rounded widths and drops (think of it as a vertical length) respectively, effectively creating a matrix of sizes that are engineered with components that are stored in other fields in the table. So, for instance, if our entered width is 1450, a previous UDM finds the closest larger size to round up to, in this case 1500. Clear as mud?
My UDMs to find the rounded sizes work just fine. My problem arises when I try to feed the sizes back in to find other specs. Because the sizes are held in Key fields, I think my LINQ is interpreting my strings as numbers and crashing because it finds an incorrect data type.
As a practical example, here’s my UD Method. Two string parameters are passed in sWidth and sDrop
string sReturn = "";
try
{
var sp = (from ud in Db.UD11
where ud.Company == "XXXX"
&& ud.Key1 == Inputs.txtConfigID.Value
&& ud.Key3 == "Spring"
&& UD.Key4 == sWidth
&& UD.Key5 == sDrop
select new {
wd = ud.Key4,
dr = ud.Key5,
co = ud.ValueStr_c
}).ToList();
sReturn += "\nsp Count = " + sp.Count.ToString();
}
catch (Exception ex)
{
sReturn += "\nError in UDMethod.LookupUD11Spring:\n" + ex.Message;
}
return sReturn;
This runs fine but returns 0 rows. If I substitute the string sizes in instead of the parameters it all works and I find the row I expect. So the following code works just fine:
var sp = (from ud in Db.UD11
where ud.Company == "XXXX"
&& ud.Key1 == Inputs.txtConfigID.Value
&& ud.Key3 == "Spring"
&& UD.Key4 == "2300"
&& UD.Key5 == "2000"
select new {
wd = ud.Key4,
dr = ud.Key5,
co = ud.ValueStr_c
}).ToList();
I think LINQ is interpreting my parameters as numbers, even though they’re passed in as strings, so it’s being seen as ud.Key4 == 2300 instead of ud.Key4 == "2300", and it therefore doesn’t find the droids I’m looking for.
I’ve tried umpteen different variations of casting to string and the UD Method likes the syntax, but I’ve had no success. Some come back with 0 rows, others hit my catch and give various error messages.
Can anyone point me in the right direction? Thanks in advance!
Ryan


