First Post / How to access TypeList with LINQ?

Posts   
 
    
pkellner avatar
pkellner
User
Posts: 19
Joined: 23-Aug-2009
# Posted on: 23-Aug-2009 02:39:29   

So, I've read through the docs (once only) and have started to understand how things fit together, but not very well so please excuse my lack of understanding basic type questions. Maybe this is not a LINQ question, who knows. Couple questions follow:

So, I Created a project and added all my 25 tables as entities. I can successfully query one table as follows:

using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.ConnectionString = "Data Source=.;Initial Catalog=svcodecamp ;Persist Security Info=True;User ID=sa  ;Password=xxx";
                LinqMetaData metaData = new LinqMetaData(adapter);
                var q = from data in metaData.CodeCampYear select data;
                foreach (var entity in q)
                {
                    Console.WriteLine(entity.CampStartDate);
                }
            }

I also created a TypedLists by dragging 4 tables to the TypedLists section on the right. I was half expecting that assocaited with metaData I could type the name of my TypedList (metaData.SessionsWithTagsAndAttendees), but my wish was not granted. My question is can you get at this typedList data through LINQ to LLBL?

Second question is around references. I don't fully grock how the references are working. It seems to keep promping me (I"m using resharper) to add references. It currently shows the following references against my small unit test project. (SD.LLBLGen.Pro.LinqSupportClasses.NET35;SD.LLBLGen.Pro.ORMSupportClasses.NET20 and svcodecampDBSpecific). Is this what should have happened? Should I have added these by hand first then all would be good?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 23-Aug-2009 11:58:58   

pkellner wrote:

So, I've read through the docs (once only) and have started to understand how things fit together, but not very well so please excuse my lack of understanding basic type questions. Maybe this is not a LINQ question, who knows. Couple questions follow:

So, I Created a project and added all my 25 tables as entities. I can successfully query one table as follows:

using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.ConnectionString = "Data Source=.;Initial Catalog=svcodecamp ;Persist Security Info=True;User ID=sa  ;Password=xxx";
                LinqMetaData metaData = new LinqMetaData(adapter);
                var q = from data in metaData.CodeCampYear select data;
                foreach (var entity in q)
                {
                    Console.WriteLine(entity.CampStartDate);
                }
            }

I also created a TypedLists by dragging 4 tables to the TypedLists section on the right. I was half expecting that assocaited with metaData I could type the name of my TypedList (metaData.SessionsWithTagsAndAttendees), but my wish was not granted. My question is can you get at this typedList data through LINQ to LLBL?

Not at the moment as in: you can't fetch them with Linq statements. The main reason is that they're datatables and by adding them to metaData, it would make it possible to join with normal entities which would likely cause problems during fetching because for example things wouldn't be joinable at runtime. Typed lists are present since the beginning to give a typed kind of list which was build on top of entities. With linq and typed projections from a set of entities, typed lists have become a bit obsolete, as you can also write the same query in a couple of linq statements and a custom projection.

So v2.6, linq to llblgen pro is limited to entities.

We're looking into generating typed lists as linq queries in the next version.

Second question is around references. I don't fully grock how the references are working. It seems to keep promping me (I"m using resharper) to add references. It currently shows the following references against my small unit test project. (SD.LLBLGen.Pro.LinqSupportClasses.NET35;SD.LLBLGen.Pro.ORMSupportClasses.NET20 and svcodecampDBSpecific). Is this what should have happened? Should I have added these by hand first then all would be good? Thanks

The generated code projects have the right references in the generated vs.net projects. For your own code, you reference the two generated vs.net projects, SD.LLBLGen.Pro.LinqSupportClasses.NET35 and SD.LLBLGen.Pro.ORMSupportClasses.NET20. You don't need to reference the DQE nor a db provider dll in your own code.

Frans Bouma | Lead developer LLBLGen Pro
pkellner avatar
pkellner
User
Posts: 19
Joined: 23-Aug-2009
# Posted on: 23-Aug-2009 18:09:06   

Thanks for the info on TypedLists. No problem. I'll stay away from them. I'm trying to figure out the best way to rewrite my "management" layer between my app and llblgen and best take advantage of what's out there. I'm just struggling with that some. I don't want to just copy my linq2sql stuff because I'vel earned so much since first creating that.

Also, I'm still a bit confused on the references. When I simply create a new project, add references to the two llbl projects generated, I can't compile. When I turn resharper on, it suggests some reference additions (plus asks me to add xml serialization reference), then it works. I feel like I must be doing something wrong.

I've done a short (though big) snagit video to show what I've done. It's about 100 meg and you can grab it here.

http://peterkellner.net/misc/DemoOfCreatingNewLLBLProject.zip

Thanks,

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Aug-2009 21:38:42   

Also, I'm still a bit confused on the references. When I simply create a new project, add references to the two llbl projects generated, I can't compile. When I turn resharper on, it suggests some reference additions (plus asks me to add xml serialization reference), then it works. I feel like I must be doing something wrong.

Hi Peter,

It's all about references. You should add these references to your TestProject:

  • Your two generated-code projects (DBGeneric and DBSpecific)
  • LLBLGenPro ORMSupportClasses
  • System.Xml. This assembly isn't added by default on new VS.Net Test projects, and some classes of LLBLGenPro uses System.Xml.

So, keep doing like you did on your "WithResharper....avi" video.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 24-Aug-2009 14:47:17   

Ok saw the video. Couple of things: 1) with VS.NET 2008 sp1 you get the 'squiggly' red underlining without resharper as well, which would suggest to you to add using statements 2) the System.Xml namespace is required, because the ormsupportclasses refers to it. It apparently has to be in your references list otherwise the application you're building might not run properly, according to the compiler. (i.e. indirect referenced assemblies also have to be in your project).

Hope this clears things up a bit. I wished vs.net was clever enough to add the references required to a .exe project which references the generated code, but alas...

I also added a little more detail to the Compiling the code section about t is, as it wasn't as clear as intended.

Frans Bouma | Lead developer LLBLGen Pro
hypo
User
Posts: 34
Joined: 14-Oct-2008
# Posted on: 08-Sep-2009 16:41:17   

I'm gonna give the Linq on TypedList a try through this piece of code: http://cs.rthand.com/blogs/blog_with_righthand/archive/2006/01/15/284.aspx

I also do like the TypedLists as I use them as my Queries in the Command and Query Seperation Pattern I implement in my project!!

Kind regards, Wim

hypo
User
Posts: 34
Joined: 14-Oct-2008
# Posted on: 08-Sep-2009 17:07:18   

Seems to work great!

 public void ShowPlannedAppointments(UserAppointmentsTypedList aUserAppointmentsList)
        {

            var rows = new LinqList<UserAppointmentsRow>(aUserAppointmentsList.Rows);
            
            var selectedRows = (from r in rows
                                select new {r.AddressId, r.AppointmentId}).Distinct();

Kind regards, Wim