Use TableAdapter to update datatable back to database

Posts   
 
    
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 12-Oct-2007 20:49:05   

With datatsets, especially typed datasets in VS.NET 2005, it is simple.

You have a table adapter (or data adapter) that has an update method. This update method takes care of updating the database with cnay changes (inserts, updates, deletes).

I use GetMultiAsDataTable to get a data table of records. I modify them in the UI. I want to send this modified datatable back to the database. If any records were modifed, added, or deleted, the LLBLGen DAO would take care of sending the proper command to the database to sync it.

This is simple to do in VS 2005 with a typed dataset. Example shown:

To fill a typed dataset (lutblZone)

    Dim ta As New dsZoneTableAdapters.lutblZoneTableAdapter()
    Dim ds As New dsZone
    ta.Fill(ds.lutblZone)

To update this back into the database I simply do the following: This will send any update, insert, delete queries it needs to send to the database

        Dim ta As New dsZoneTableAdapters.lutblZoneTableAdapter()
        ta.Update(ugZoneMachine.DataSource)

This is so simple. All I need to do is create a types dataset in my project - all the SQL code required to get and change data is sone behind the scenes.

How can I do this in LLBLGen Pro? I know how to get the data table, I just do not know how to send updates from the data table back to the database easily. I do not want to use the LLBLGen Entity or Collection classes for this purpose.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 12-Oct-2007 22:58:16   

Typed/dynamic lists are designed for 1 way, read-only data. they do not map 1:1 with the database tables/entities. for ready/write you should use entities.

CustomerEntity customer = new CustomerEntity(1);
customer.Name = "Foo";
customer.Save();

I think that's write. I use the adapter pattern. see the docs for more information.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Oct-2007 07:32:14   

As jmeckley says, TypedList, DynamicLists, TypedViews and results in DataTables are intended for one-way/read-only purposes. Reading these threads could clarify that: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4146 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=9626

Could you explain your scenario, so you don't want to use EntityCollections?

David Elizondo | LLBLGen Support Team
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 13-Oct-2007 22:13:20   

I do not want to use entity collections because I want a layer between my user interface and LLBLGen Pro. I don't want the UI to even know what a LLBLGen Pro Entity Collection is. I prefer dealing with custom business objects and standard .NET objects (ie datasets). My UI deals directly with a facade layer which deals with the data layer (LLBLGen Pro). This will make future maintenance easier and allow me to swap out or change the data layer or even distribute the data layer onto another server. I do not want any LLBLGen specifc code in my User Interface. Now, how I get my data, I like LLBLGen Pro's retrieval methods, but I also like the typed dataset approach with VS.NET 2005. It's a shame this can't be accomplished with LLBLGen Pro.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 15-Oct-2007 05:19:57   

Dan1 wrote:

I like LLBLGen Pro's retrieval methods, but I also like the typed dataset approach with VS.NET 2005. It's a shame this can't be accomplished with LLBLGen Pro.

Did you realize how LLBL works before implementing it as your solution? This might sound trite, but your trying to use LLBL in a manner it wasn't designed for.

I see three options 1. stop using typed datasets for read/write operations and switch to LLBL collections 2. stop using LLBL as your DAL an use a different orm tool based upon datasets 3. create a set of adapters to convert entity collections to typed dataset and vice versa.

Personally I would choose option 1 followed in a distant 2nd by option 2.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2007 05:50:38   

jmeckley wrote:

  1. create a set of adapters to convert entity collections to typed dataset and vice versa.

As Jason says, there's many threads at forum explaining how to use DTO's in conjunction with LLBLGenPro

David Elizondo | LLBLGen Support Team
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 15-Oct-2007 14:14:57   

So your saying because I want to have a disconnection between my User Interface and the LLBGen Pro Data Layer I should use a different tool or not use LLBLGen Pro?

Surely you can understand why I would not want the client user interface to directly reference the data layer.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 15-Oct-2007 14:22:21   

which model are you using? Adapter or SS. SS allows lazy loading. so the UI can get whatever they want, when ever they want. If you want to control when/how data is fetched the adapter pattern allows for this. The entities represent the model which interact with the UI. however, if the UI wants data from the db they must use an adapter. this could be controled through business logic.

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 15-Oct-2007 14:25:33   

Maybe I will use .NET Typed Data Sets for when I need a dataset as I can do everything I need with them (sorting, filtering, updating) very easily and only use LLBLGen Pro when I need to project data into a Business Object - I suppose I could create my own class to project data from a typed dataset to a custom busines object and then back.

I have no interest in referencing an LLBLGen Pro Entity object directly in my User Interface.

Maybe I am using LLBLGen Pro incorrectly, but the only feature I seem to need from an SOA standpoint is the data projecting and the filtering/sorting abilities.

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 15-Oct-2007 22:11:01   

Maybe I am using LLBLGen Pro incorrectly, but the only feature I seem to need from an SOA standpoint is the data projecting and the filtering/sorting abilities.

That's not clear. You seem to me to be saying why doesn't this dog meow. From reading the posts, so far, it's not clear what you are hoping to accomplish, only how you want to accomplish it.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Oct-2007 10:29:35   

I see three options 1. stop using typed datasets for read/write operations and switch to LLBL collections 2. stop using LLBL as your DAL an use a different orm tool based upon datasets 3. create a set of adapters to convert entity collections to typed dataset and vice versa.

Personally I would choose option 1 followed in a distant 2nd by option 2.

In your case, I'd recommend using Option 3. Especially that you can use the Projection Feature of LLBLGen Pro to project data from en EntityCollection's EntityView to DataTable or a List<CustomClass>. (ref: manual "Using the generated code -> Adapter/SelfServicing -> Using the EntityView class")

And you can project the results read by a DataReader into an EntityCollection. (ref: manual "Using the generated code -> Adapter/SelfServicing -> Fetching DataReaders and projections")

Also you can try out the DTO (Data Transfer Objects) templates. (check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10504)