Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sorry a very simple question for more experienced programmers.
How to I cast a linq to sql query to a decimal and return it from a function?

The (decimal) cast below doesn't work.

Thanks for the help!

What I have tried:

C#
static decimal GET_MC_DATA_EAV(int ID, string B_C, string GREEK, int DP_NO)
{

     var qryMC = Globals.DATA.MONTECARLO_EAVs.Where(Z => Z.BOOK_COMP == B_C && Z.BOOK_ID == ID && Z.GREEK == GREEK && Z.DP_NO == DP_NO).Select(Z=>Z.DATA).Single();
           
                  return (decimal)qryMC;    
}
Posted
Updated 15-Mar-16 3:37am
v5
Comments
F-ES Sitecore 15-Mar-16 8:54am    
What type is qryMC?
Richard MacCutchan 15-Mar-16 8:55am    
What type is qryMC? Using var just makes it impossible to guess. But assuming it is one of the base types, such as int, you cannot cast it to a decimal. Read the documentation for using casts.
[no name] 15-Mar-16 9:00am    
What is type qryMC and MONTECARLO_EAVs ?
Trader999 15-Mar-16 9:22am    
tks for your answers. Z.DATA will be of decimal type. If i replace var with decimal I get a compile error.
CHill60 15-Mar-16 9:25am    
They actually asked what type was qryMC! If you hover your mouse over the var then Visual Studio will tell you the type

1 solution

Answered only to remove from unanswered list: solved by OP (with a little help!)
 
Share this answer
 
v2
Comments
Trader999 15-Mar-16 9:52am    
tks everyone

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900