views:

163

answers:

1

I asked on SO a few days ago what was the simplest quickest way to build a wrapper around a recently completed database. I took the advice and used sqlmetal to build linq classes around my database design.

Now I am having two problems. One, I don't know LINQ. And, two, I have been shocked to realize how hard it is to learn. I have a book on LINQ (Linq In Action by Manning) and it has helped some but at the end of the day it is going to take me a couple of weeks to get traction and I need to make some progress on my project today.

So, I am looking for some help getting started.

Click HERE To see my simple database schema.
Click HERE to see the vb class that was generated for the schema.

My needs are simple. I have a console app. The main table is the SupplyModel table. Most of the other tables are child tables of the SupplyModel table.

I want to iterate through each of Supply Model records. I want to grab the data for a supply model and then DoStuff with the data. And I also need to iterate through the child records, for each supply model, for example the NumberedInventories and DoStuff with that as well.

I need help doing this in VB rather than C# if possible. I am not looking for the whole solution...if you can supply a couple of code-snippets to get me on my way that would be great.

Thanks for your help.

EDIT
For the record I have already written the following code...

Dim _dataContext As DataContext = New DataContext(ConnectionStrings("SupplyModelDB").ConnectionString)
Dim SMs As Table(Of Data.SupplyModels) = _dataContext.GetTable(Of Data.SupplyModels)()
Dim query = From sm In SMs Where sm.SupplyModelID = 1 Select sm

This code is working...I have a query object and I can use ObjectDumper to enumerate and dump the data...but I still can't figure it out...because ObjectDumper uses reflection and other language constructs I don't get. It DOES enumerate both the parent and child data just like I want (when level=2).

PLEASE HELP...I'M stuck. Help!

Seth

+1  A: 

in C# it would be:

    var result = from s in _dataContent.SupplyModels where s.SupplyModelID==1 select s;
    foreach(SupplyModel item in result)
    {
       // do stuff
       foreach(SupplyModelChild child in item.SupplyModelChilds)
       {
          //do more stuff on the child
       }
    }

and a VB.NET version (from the Telerik code converter)

Dim result As var = From s In _dataContent.SupplyModels _
    Where s.SupplyModelID = 1 _
    Select s
For Each item As SupplyModel In result
    ' do stuff
            'do more stuff on the child
    For Each child As SupplyModelChild In item.SupplyModelChilds
    Next
Next
Andrew Lewis
Telerik code converter: http://converter.telerik.com/
Andrew Lewis
Thanks...that did it...that was simple...the problem is that most of my code was using implicit typing which means I did not know what kind of types were being referenced and no intellisense.
Seth Spearman