Which to use, SelfServicing or Adapter?

Posts   
 
    
sdgrow
User
Posts: 11
Joined: 01-Nov-2009
# Posted on: 05-Nov-2009 05:39:09   

I am a little confused as to which method I should use...

I primarily need the features in the Adapter but there are a couple that I would like to have from the SelfServicing as well. An example is:

  • When you need navigation through your object model in a databinding scenario and you want to load the data using lazy loading.

Do I have to pick one method or can I mix them.

Regards, Sam

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 05-Nov-2009 07:21:09   

Hi Sam -

Welcome to LLBLGen Pro. Rest assured - You are in the best of hands here.

Self-Servicing & Adapter - What they have in Common

Self-Servicing & Adapter both give you everything you need to work with your database. They both accomplish the exact same things. Most of the generated code for both of them will look identical to your application. For instance, both will give you a CustomerEntity. And you can access things like CustomerEntity.CustomerName, etc. And you can walk relationships like myCustomer.Orders will give you a collection of that Customer's OrderEntities.

Self-Servicing & Adapter - How they are Different

The real difference between Self-Servicing & Adapter is where the communication to the database occurs. In Self-Servicing, each Entity can communicate directly to the database. In Adapter, each Entity cannot communicate directly to the database; instead, you use an Adapter (which represents the database connection), and pass it the Entities. In either case - all you will be doing are: Fetch/Save/Delete. Everything else between Self-Servicing & Adapter is basically identical.

Self-Servicing & Adapter - How do you choose?

As Frans would say - it depends on what you need.

If you're developing a quick app or you will be the sole developer - you can go for Self-Servicing. Self-Servicing is great if you really just want your data. Although, Self-Servicing is discouraged for development teams - because your UI developers will have direct access to the database, without going through a business layer. At a certain point, you lose control of what's going on.

If you're developing a real business app - go directly to Adapter; If you pass Go, Collection $200. smile Adapter is the professional, enterprise-grade data access mode.

Although Self-Servicing is very fast to learn & get started with, it also allows for laziness (no pun intended) on the developer's part. This can be dangerous.

Using Self-Servicing, You can really slow down your app unintentionally. For instance, if you forget to Prefetch something into your Graph - and it is accessed - it will be Lazy-loaded for each entity that references it. For instance, if you have 50 Products and forget to Prefetch the ProductType... You will make 50 separate lazy-load database calls to get each ProductType. Rather, if you had Prefetched the ProductType - it would only have been 1 query. All these little mistakes add up & unless you are very intentional about what you're doing - it will cause slow-downs in your app, and you'll be left trying to figure out what's slowing your app down.

In development teams - Self-Servicing can be dangerous because it's really hard to centralize your business logic / processes... when a UI developer is having a lazy day and starts talking directly to the database... bypassing all your business logic. And you likely won't find these problems until later. Something to the effect: Why is this Order still in state ABC... when it should be in XYZ?? Big Whoops.

Adapter prevents you from making these mistakes, and forces you to know exactly what is going into the EntityGraph. Adapter also gives you central control over your business processes, because the Entities cannot talk directly to the database - they cannot bypass your business logic.

Hope this helps!

Ryan

PS 1.) You cannot mix Self-Servicing entities with Adapter entities.

PS 2.) Using Adapter, You can certainly add Entities into your Entity Graph that weren't initially Fetched/Prefetched. To do this, look at the Context. It will allow you to extend your existing Graph with more Entities.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-Nov-2009 10:16:32   

Beside what's written in the docs: When to use which template group?, Ryan has said it all.

sdgrow
User
Posts: 11
Joined: 01-Nov-2009
# Posted on: 05-Nov-2009 18:45:26   

Hi Ryan,

Thanks for that detailed reply, it really helps me a lot. There is no question I will want to use Adapters based on what you said.

Thanks to you too Walaa.

Thanks, Sam