using llblgen with database views

Posts   
 
    
andieje
User
Posts: 28
Joined: 17-May-2006
# Posted on: 15-Jun-2006 16:20:21   

Hi

Consider the basic database design where you have a customer table and a country table. The customer table has a field called CountryID which stores the PK of the country the customer is from.

In this case I normally create a view of the customer table that contains the field CountryName rather than countryid. This view is created by joining the customer table to the country table as so

select cust.*, country.countryname from cust inner join country on cust.countryID = country.countryID

In LLBLGen, if i had an entity based on this view, how would inserts and updates be handled.

For example, would the insert method (or equivalent) on the customer entity contain an attribute called CountryID or CountryName. In other words would you have to supply an insert method with a countryID or a countryname in order to insert a customer record.

If the upset/update methods take a countryName, how is this handled behind the scenes (as the customer table actually has a countryID field)

Thansk very much andrea

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Jun-2006 22:58:32   

I believe that sql only allows a view to update one table. So the CountryId field would be changed, but nothing could be inserted into Country from this view.

If you want you can setup the CountryName as a field on a related field in the designer and then prefetch the Country when you load the customer. Then if you needed to do anything with the country customer.Country would be available and if you were showing a grid with customers then customer.CountryName would be available.