1

Firstly I would like to apologize to you all because I know that this question has been asked a whole bunch of times. But I dont know much about MVC or .NET or Lambda expressions per se. I am working on a small project and I am stuck at the Lambda expression error as below enter image description here

EDIT Below is the controller Code

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC4Trial.Models;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

namespace MVC4Trial.Controllers
{
    public partial class CallTrackController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Remote_Data()
        {
            return View("AjaxBinding");
        }

        public ActionResult vwCallDetails([DataSourceRequest] DataSourceRequest request)
        {

            return Json(GetCallDetailsFn().ToDataSourceResult(request));
        }

        private static IEnumerable<CallDetails> GetCallDetailsFn()
        {
            var callData = new CallTrackClassDataContext();
            return callData.CallDetails.Select(calldetail => new CallDetails
            {
                CCCID = calldetail.CCCID,
                Mp3_Url = calldetail.Mp3_Url,
                Index = calldetail.Index,
                Target_Number = calldetail.Target_Number,
                Duration = calldetail.Duration,
                LocalTime = calldetail.LocalTime,
                Site_Name___Address = calldetail.Site_Name___Address,
                Ad_Source_Name = calldetail.Ad_Source_Name,
                Tracking_Number = calldetail.Tracking_Number,
                Caller_Number = calldetail.Caller_Number,
                Available_Feature = calldetail.Available_Feature


            });
        }


     }
}

I would like to learn how to fix this error. What am I missing here? Do I need to make any sort of changes on my Model/View/Any other file? Thanks for reading and helping.

4
  • A screenshot is nice, but can you post the text of the code so others wouldn't need to retype it? Commented Feb 14, 2013 at 21:22
  • 1
    What's the error on the 'Duration' line? I've notice that other errors will cause linq errors. Commented Feb 14, 2013 at 21:22
  • I notice Duration is underlined - is there something special about that property? Commented Feb 14, 2013 at 21:22
  • Thank you all for helping out so quickly! Commented Feb 14, 2013 at 21:34

1 Answer 1

3

There's something wrong with Duration. It's underlined in red, indicating that it doesn't exist on the class, or some other issue is causing it to not be recognized. Since there's an error here, the lambda expression doesn't process properly and it's only then that Visual Studio recognizes there error. Essentially, the reported error is masking the true problem. Fix Duration or remove it, and the lambda expression will be fine.

For what it's worth though, what you're doing doesn't make much sense. callData.CallDetails already returns an instance of CallDetails (or at least it should, or you should change the name), so using Select to return an instance of CallDetails populated from an instance of CallDetails is superfluous.

UPDATE

Sorry for not being more clear. My last comment really depends on what is exactly going on in code I can't see. So there's two possible scenarios:

1) callData.CallDetails is an instance of CallDetails. If this is the case, using Select is a waste of time and code because all you're doing is just converting one instance of CallDetails to another. Just doing return callData.CallDetails; would have the same effect.

2) callData.CallDetails is not an instance of CallDetails. If this is the case, then you should simply rename the CallDetails member of callData to avoid the sort of confusion that prompted my comment in the first place.

FWIW: If you really need to map some other type to an instance of CallDetails like this, you should look into AutoMapper. Writing this code is not only repetitive and time-consuming, but you also make yourself more prone to errors. For example, what if you later change the definition of CallDetails? You now got to track down every explicit mapping like this and change that as well, whereas with AutoMapper, you likely can just change the definition and be done.

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

2 Comments

I fixed the problem by fixing the Duration Column. I will accept the answer shortly when SO lets me do it. What other change would you suggest to the code to get rid of the "superfluous"ness? I am sorry, I dont sound too technical, but I am a database guy and this is the first time I am playing with apps.
@rvphx: Perhaps move the copy/conversion code you have in the Select() portion to a dedicated method. I'm not sure if you're simply cloning the same class or copying to/from a separate data-transfer object (DTO), so I'm not sure the best place for this method to reside. At the very least it will make your code more readable.

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.