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

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.
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. FixDurationor 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.CallDetailsalready returns an instance ofCallDetails(or at least it should, or you should change the name), so usingSelectto return an instance ofCallDetailspopulated from an instance ofCallDetailsis 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.CallDetailsis an instance ofCallDetails. If this is the case, usingSelectis a waste of time and code because all you’re doing is just converting one instance ofCallDetailsto another. Just doingreturn callData.CallDetails;would have the same effect.2)
callData.CallDetailsis not an instance ofCallDetails. If this is the case, then you should simply rename theCallDetailsmember ofcallDatato 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
CallDetailslike 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 ofCallDetails? 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.