Method call in LINQ column

I have the following LINQ query:

//myRepository.GetClients(); returns an IQueriable<>
        var AllClients = myRepository.GetClients();


        var ClientReports = from c in FirmECFIs
                         select new ClientReport
                        {
                            FirmSerialNumber = c.SerialNumber,
                            FirmName = c.Name,
                            Year = c.Year,
                            Month = c.Month,
                            CustID = c.CustID,
                            TotalCount =myRepository.GetCount(c.SerialNumber, billingYear, billingMonth),
                            TotalPrice = "0"
                        };

I get the error "... does not support translating to SQL" When I remove a method call from the TotalCount column and assign a static value, it works fine. Looks liek LINQ cannot translate method call to tSQL

Can anyone help me with this?

thank

Source of the GetCount () method:

        public int GetCount(int SerialNumber, string billingYear, string billingMonth)
    {
        var Count = CreateDataContext().myView.Where(c => c.SerialNumber == SerialNumber)
            .Where(c => c.Year == Convert.ToInt32(billingYear)).Where(c => c.Month == Convert.ToInt32(billingMonth));
        return Count.ToList().Count;
+3
source share
2 answers

Your repository does not do its job very well here - in fact, it is a very impenetrable abstraction, which at best will not help you (since you are still requesting outside the repository).

GetClientReports , . , Linq to Sql, .

+3

SQL/LINQ , #. SQL.

+2

All Articles