Building Entities from IList or DataTable

Posts   
 
    
Insane
User
Posts: 10
Joined: 19-Sep-2006
# Posted on: 20-Sep-2006 13:56:31   

Hi, I am a newbie.

In my scenario I have seperated my Interface of my Data / Business Layer. I use my Business Layer as a service and Clients don't have LLBL reference.

I can send Data to Clients using IList or Projections. Client, updates data binded to grid or form and sends it back to Business Layer Service.

I want to update more than one row at a time. What's the easiest way to construct and update Entity Collections from DataTable or IList?

I have tried the EntityCollection Constructor but somehow it didn't work.

My code is;

// i can save the package entity without problem PackageEntity pack = new PackageEntity(package.PackageID); pack.PackageName = package.PackageName; pack.PackageDescription = package.PackageDescription; pack.Save();

// I have Products & Product Quotas which belongs to a Package and I want to update them. package.QuotaTable has records but this doesn't load data into ProductQuotaCollection.

        ProductQuotaCollection pQuotas = new ProductQuotaCollection((IList<ProductQuotaEntity>)package.QuotaTable);
        pQuotas.SaveMulti();

Also I am trying to do this stateless. I mean there may be no ProductQuotaCollection loaded at server. So I thing first I have to load them, update and save changes.

Thanks for help...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2006 15:13:17   

You may use DataReaders and project them to EntityCollections. Please refer to the v.2 manual "Using the generated code -> Adapter/SelfServicing -> Fetching DataReaders and projections"

Insane
User
Posts: 10
Joined: 19-Sep-2006
# Posted on: 20-Sep-2006 15:54:04   

I don't get it.

I already get the updated data from client. (IList or DataTable format) I just want to update it back into DB.

I read that section but that was only about fetching data.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 18:00:57   

BUt what data is new and what data is changed and what data hasn't changed? That's unclear unless you're using entity classes which contain tracking info. So a class with just properties or a datatable, it doesn't contain tracking info if the data is new/changed or not changed. You then have to load the entities, set the values and save the entities.

Frans Bouma | Lead developer LLBLGen Pro
Insane
User
Posts: 10
Joined: 19-Sep-2006
# Posted on: 05-Oct-2006 10:55:46   

I have solved this issue by sending DataTables between business layer and interface. I use stateless objects at business layer and don't track changes at that level.

When client changes its bindings, it sends back only a subset which is datatable.GetChanges() so i can insert / update / delete which is necessary at business layer using that subset.

It seems to me is the only "not so redundant way" to do this kind of seperation.