Linq to LLBLGen Stored procedures

Posts   
 
    
jbreuer
User
Posts: 43
Joined: 30-Nov-2009
# Posted on: 03-Dec-2009 17:08:05   

Is it possible to use Linq to LLBLGen to fetch data from Stored procedures? I would like to do the same as the next example:

http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 03-Dec-2009 18:34:21   

no that's currently not supported (also not planned for v3), you need projections for that or use the calls generated.

Frans Bouma | Lead developer LLBLGen Pro
jbreuer
User
Posts: 43
Joined: 30-Nov-2009
# Posted on: 04-Dec-2009 08:29:37   

Otis wrote:

no that's currently not supported (also not planned for v3), you need projections for that or use the calls generated.

Too bad it's not supported. Would make things a lot easier. Currently I've the following code but there must be an easier way to do this:


UmbracoProductCollection umbracoProductCollection = new UmbracoProductCollection();
            using (IRetrievalQuery query = RetrievalProcedures.GetSpDigiGetRecursiveUmbracoProductsCallAsQuery(productGroupCode))
            {
                TypedListDAO dao = new TypedListDAO();
                using (IDataReader reader = dao.GetAsDataReader(null, query, CommandBehavior.CloseConnection))
                {
                    List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
                    valueProjectors.Add(new DataValueProjector(UmbracoProductFieldIndex.UmbracoProductId.ToString(), 0, typeof(Guid)));
                    valueProjectors.Add(new DataValueProjector(UmbracoProductFieldIndex.FirstProductName.ToString(), 1, typeof(string)));
                    DataProjectorToIEntityCollection projector = new DataProjectorToIEntityCollection(umbracoProductCollection);
                    dao.GetAsProjection(valueProjectors, projector, reader);
                }
            }

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Dec-2009 08:34:25   

Currently I've the following code but there must be an easier way to do this:

That's the only way to go if you want projection.

jbreuer
User
Posts: 43
Joined: 30-Nov-2009
# Posted on: 04-Dec-2009 08:35:26   

Walaa wrote:

That's the only way to go if you want projection.

And what are the other options besides projection?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Dec-2009 08:55:16   

Use call the SP and having the results returned in a dataTable.

jbreuer
User
Posts: 43
Joined: 30-Nov-2009
# Posted on: 04-Dec-2009 08:56:42   

Walaa wrote:

Ust call the SP and having the results returned in a dataTable.

And is there an easy way to convert a datatable into an EntityCollection or can this only be done using projections?

Thank you for the help so far!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Dec-2009 12:01:51   

Either projection or use your own code that copies values from the database into an entities that gets added to the EntityCollection, but no point in doing that when you can just use the projection. (In fact I don't think the projection code is too much to use).

jbreuer
User
Posts: 43
Joined: 30-Nov-2009
# Posted on: 04-Dec-2009 14:41:05   

I created my own generic method to convert a Stored Procedure to a collection. You can find it here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=17023&StartAtMessage=0&#95330