Cannot convert lambda expression to type 'string' because it is not a delegate type--By Kevin

I got an old problem but I couldn't find correct answer here .

Can any body tell me the answer?

using System;
using System.Linq;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using MvcApplication1.Models;



public ActionResult Edit(int id)
    {
        //return View();
        var maintableToEdit = (from m in _DB.mainTable where m.Id = id select m).First();

        return View(maintableToEdit);


    }

Error 1 Cannot convert lambda expression to type 'string' because it is not a delegate type C:\Users\Administrator\Documents\Visual Studio 2008\Projects\localhost\MvcApplication1\Controllers\HomeController.cs 80 60 MvcApplication1

Error 3 'MvcApplication1.Models.mainTable' does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'MvcApplication1.Models.mainTable' could be found (are you missing a using directive or an assembly reference?) C:\Users\Administrator\Documents\Visual Studio 2008\Projects\localhost\MvcApplication1\Controllers\HomeController.cs 81 68 MvcApplication1

Thank s a lot!!

Upvotes: 0

Views: 1082

Answers (2)

Selman Genç
Selman Genç

Reputation: 101681

Use == (equality operator) instead of = (assignment operator).

Upvotes: 2

p.s.w.g
p.s.w.g

Reputation: 149020

Use the equality (==) operator instead of assignment (=):

var maintableToEdit = (from m in _DB.mainTable where m.Id == id select m).First();

Or for brevity:

var maintableToEdit = _DB.mainTable.First(m => m.Id == id);

Upvotes: 3

Related Questions