tags:

views:

146

answers:

1

I want to make custom select from the database table using Linq. We use LLBGEN as ORM solution.

I can't do LINQ query to Entities Collection Class unless I call GetMulti(null) method of it.

Is it possible to do LINQ query to LLBGEN without extracting all table first?

BatchCollection batches = new BatchCollection();                
BatchEntity batch = batches.AsQueryable()
.Where(i => i.RegisterID == 3)
.FirstOrDefault(); // Exception: Sequence don't contains any elements

batches = new BatchCollection();                
batches.GetMulti(null); // I don't want to extract the whole table.
BatchEntity batch = batches.AsQueryable()
.Where(i => i.RegisterID == 3)
.FirstOrDefault(); //Works fine
+4  A: 

To query your database using LINQ (which is different from operating on an enumerable collection using the LINQ syntax) you have to use the LinqMetaData provider that comes with LLBLGen in the yourrootnamespace.Linq assembly. Once you add this assembly to your project you can use something like this to create your db query: (from the LLBL documentation)

LinqMetaData metaData = new LinqMetaData();
var q = from c in metaData.Customer
        where c.Country=="USA"
        select c;

In your example above you are using LINQ syntax to perform a where clause on a collection, but this does not have anything to do with LLBL or executing a query on the database. That is why it will not work with the empty collection, but does work on the filled collection.

Look more into LinqMetaData for the specifics of querying your db using LINQ to LLBLGen.

Ben Elder