blah blah blah is here! blah blah » Close

up0down
link

What are the requirements for an object (or collection) to be linq compatible?

So for my experience with linq has been with the List<T> collection, but what is the actual requirement? Is it any collection? Any object that inherts from ___?

last answered 2 years ago

2 answers

up1down
link

there's no hierarchy requirements, it operates on a number of different underlying structures. It's usually anything enumerable. you can use it with linq to sql and entity framework. though conceptually it looks the same, it builds dynamic SQL and passes that into the db instead of operating on a full data set.

up0down
link

I've used Linq on XML documents and SQL tables. Linq for SQL is, in my opinion, spectacular. No more creating a pile of objects and then building a string for your SQL command. You can think of Linq as basically like an in-line scripting system for querying data. Looking through one of my programs, I even used Linq on an array...

Codo
84

I actually found another use! It may not be the best use, but it worked. I had a short property that I was setting to the value of a short?. Obviously without an explicit cast, this causes problems....or.... you just add from Linq.... shortValue = nullableShortValue.FirstOrDefault(0);

Feedback