Learning about LINQ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 3 years ago. Improve this question Overview One of the things I’ve … Read more

The cast to value type ‘Int32’ failed because the materialized value is null

I have the following code. I’m getting error: “The cast to value type ‘Int32’ failed because the materialized value is null. Either the result type’s generic parameter or the query must use a nullable type.” when CreditHistory table has no records. var creditsSum = (from u in context.User join ch in context.CreditHistory on u.ID equals … Read more

Problem with converting int to string in Linq to entities

var items = from c in contacts select new ListItem { Value = c.ContactId, //Cannot implicitly convert type ‘int’ (ContactId) to ‘string’ (Value). Text = c.Name }; var items = from c in contacts select new ListItem { Value = c.ContactId.ToString(), //Throws exception: ToString is not supported in linq to entities. Text = c.Name }; … Read more

What’s the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

I know some differences of LINQ to Entities and LINQ to Objects which the first implements IQueryable and the second implements IEnumerable and my question scope is within EF 5. My question is what’s the technical difference(s) of those 3 methods? I see that in many situations all of them work. I also see using … Read more

“A lambda expression with a statement body cannot be converted to an expression tree”

In using the EntityFramework, I get the error “A lambda expression with a statement body cannot be converted to an expression tree” when trying to compile the following code: Obj[] myArray = objects.Select(o => { var someLocalVar = o.someVar; return new Obj() { Var1 = someLocalVar, Var2 = o.var2 }; }).ToArray(); I don’t know what … Read more

How to use DbContext.Database.SqlQuery(sql, params) with stored procedure? EF Code First CTP5

I have a stored procedure that has three parameters and I’ve been trying to use the following to return the results: context.Database.SqlQuery<myEntityType>(“mySpName”, param1, param2, param3); At first I tried using SqlParameter objects as the params but this didn’t work and threw a SqlException with the following message: Procedure or function ‘mySpName’ expects parameter ‘@param1’, which … Read more

Entity Framework VS LINQ to SQL VS ADO.NET with stored procedures? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 3 years ago. Improve this question How would you rate each of them in terms of: Performance Speed of development Neat, intuitive, maintainable code Flexibility … Read more