मेरे पास डेटाबेस तालिका लेनदेन (लेनदेन आईडी, लोकलअमाउंट ...) है। जहां स्थानीयमाउंट संपत्ति के लिए डेटाटाइप फ्लोट है। यूआई पर मैं बटन क्लिक ईवेंट पर एक पंक्ति में एसयूएम कॉलम (लोकलमाउंट) को वापस करने की कोशिश कर रहा हूं।दशमलव तक कास्टिंग LINQ से इकाइयों के प्रश्नों में समर्थित नहीं है
मैं दशमलव
के बजाय नाव हालांकि मैं कोड मैं कहाँ दशमलव के कास्टिंग कर रहा हूँ पर एक त्रुटि हो रही है का इस्तेमाल किया है
System.NotSupportedException was unhandled by user code
Message=Casting to Decimal is not supported in LINQ to Entities queries, because the required precision and scale information cannot be inferred.
public static IEnumerable<TransactionTotalForProfitcenter> GetTotalTransactionsForProfitcenter(int profitcenterID)
{
List<TransactionTotalForProfitcenter> transactions = new List<TransactionTotalForProfitcenter>();
using (var context = new CostReportEntities())
{
transactions = (from t in context.Transactions
join comp in context.Companies on t.CompanyID equals comp.CompanyID
join c in context.Countries on comp.CountryID equals c.CountryID
where c.CountryID.Equals(comp.CountryID) && t.CompanyID == comp.CompanyID
join acc in context.Accounts
on t.AccountID equals acc.AccountID
join pc in context.Profitcenters
on t.ProfitcenterID equals pc.ProfitcenterID
group t by pc.ProfitcenterCode into tProfitcenter
select new TransactionTotalForProfitcenter
{
ProfitcenterCode = tProfitcenter.Key,
//the error is occurring on the following line
TotalTransactionAmount = (decimal)tProfitcenter.Sum(t => t.LocalAmount),
//the error is occurring on the following line
TotalTransactionAmountInEUR = (decimal)tProfitcenter.Sum(t => t.AmountInEUR) //the error is occurring on this line
}
).ToList();
}
return transactions;
}
मैंने कुछ विकल्प आज़माए हैं निम्नलिखित पोस्ट लेकिन बिना किस्मत के।
किसी को भी कर सकते हैं का कहना है कि मैं क्या अन्य विकल्पों की कोशिश कर सकते हैं। LINQ के बारे में मेरा छोटा ज्ञान क्षमा करें यदि यह बहुत छोटा है।
यह व्यवहार्य लगता है लेकिन मुझे एक त्रुटि मिल रही है {"एक भौतिक 'सिस्टम से निर्दिष्ट कास्ट' सिस्टम '' प्रकार 'सिस्टम' डबल 'प्रकार वैध नहीं है।"}। ऐसा इसलिए है क्योंकि लेन-देन के लिए मॉडल क्लास में स्थानीयअमाउंट और AmountInEuro गुणों के लिए डबल शामिल है जिन्हें मैंने मैन्युअल रूप से बदल दिया है, लेकिन फिर यह वैचारिक पक्ष प्रकार 'CostReportModel.Transaction' में सदस्य 'लोकलअमाउंट' के प्रकार 'Edm.Double' के प्रकार की एक और त्रुटि देता है। ऑब्जेक्ट साइड प्रकार 'CostReportModel.Transaction' पर सदस्य 'LocalAmount' के 'System.Decimal' प्रकार से मेल नहीं खाता है। – shaz
अफसोस की बात है, वे इस प्रश्न से अलग मुद्दे हैं। ऐसा लगता है कि आप (या आपकी टीम पर कोई भी व्यक्ति) आपकी संस्थाओं के साथ झुका रहा है, जो खतरनाक हो सकता है। आपको अपने इकाई डेटा मॉडल में सुरक्षित रूप से बदलते प्रकारों पर एक अलग, ** नया ** प्रश्न की आवश्यकता हो सकती है। –
समस्या यह है कि मैंने पहले फ्लोट (ज्ञान की कमी) पर डीबी में डाटाटाइप बनाया था, फिर उन्हें दशमलव में बदल दिया (क्योंकि मुझे फॉर्मेटिंग समस्या मिल रही थी)। हालांकि, मॉडल को ईएफ द्वारा फ्लोट से डबल तक ऑटो उत्पन्न किया गया।कि अच्छा विचार फिर से इस समाधान का प्रयास करने के इकाई वर्ग उत्पन्न करने के लिए होगा? – shaz