Talking to Tables and Views

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 05-Nov-2007 11:39:44   

The application I am working on at the moment uses a View and a Table per entity. All reads are done from the View and Inserts/Updates are done to the Table. The View often contains denormalized data and the like.

Now although LLBLGenPro can create an entity based on a View, there is of course a problem when the View is not-updateable.

I was wondering whether it would be possible to write a custom DataAccessAdapter that looks for "_VIEW" at the end of the database target and 'removes' that bit when inserting/updating. Rereads would need to use the target name as-is.

How easy would this be to do and can anyone see any pitfalls?

Cheers Simon

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 05-Nov-2007 22:06:26   

Hi simmotech, I think that unless you have a very good reason to do it you should try to avoid that kind of solution, it seems cumbersome to me, like I said before I don't know the circumstances of your case. the caveats i can think of are the following: performance degradation and hard maintenance code (in the new adapter class, the one you'll create)

So, is it possible, yes, but somehow cumbersome to me.

Maybe you could elaborate a little more on your context of your solution.

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 06-Nov-2007 06:50:42   

goose wrote:

Hi simmotech, I think that unless you have a very good reason to do it you should try to avoid that kind of solution, it seems cumbersome to me, like I said before I don't know the circumstances of your case. the caveats i can think of are the following: performance degradation and hard maintenance code (in the new adapter class, the one you'll create)

So, is it possible, yes, but somehow cumbersome to me.

Maybe you could elaborate a little more on your context of your solution.

Its an existing (fairly large) application so there is no chance of changing it really. It uses an in-house derivative of something called Nexor. Basically you write an XML file for each entity including a TableName and a ViewName and then define the fields (View columns have a separate attribute so they are never written back). Entities are then generated from a template file.

So given that it isn't practical in this project to change everything to LLBLGenPro, I was wondering about running LLBLGenPro side-by-side for new modules (and possible gradual replacement of existing stuff in the future).

The simplest thing I could think of is to emulate what happens now: read from the View but write to the Table and since we have a convention that the view is called "<tablename>_VIEW" I was hoping it would be easy to detect this and make it transparent.

Cheers Simon

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Nov-2007 09:09:21   

The best place I can think of to handle this is in your code (eg. the BL). You should the View entity for reads, and use the table one from writes.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 06-Nov-2007 11:22:09   

You could use OnSaveEntity and override that method and alter the passed in IActionQuery object's sql string (in Command): replace "_VIEW" with ""

Frans Bouma | Lead developer LLBLGen Pro