1

I am quite new to entity framework and linq but basically I am using data first and my database has a table called tblNumbers and it has 2 columns, an id column and a numbers column which is populated with int values, I want to populate only the number values into my list but when I try do this I get an error saying that I cannot implicitly convert system.collections.generic.list< int> to system.collections.generic.list<projectname.Models.tblNumber>. I am not sure where to go from this, any help would be much appreciated.

Here is my code:

private DatabaseEntities db = new DatabaseEntities();

public ActionResult MyAction()
{
    db.Configuration.ProxyCreationEnabled = false;
    List<tblNumber> numbers = db.tblNumbers.Select(column => column.numbers).ToList();
    return View();
}

1 Answer 1

1

Your List<tblNumber> numbers is expecting a list of tblNumber type and you are selecting column.numbers only

var numbers = db.tblNumbers.Select(column => column.numbers).ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I understand now.

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.