Model-First/Model-Only

Posts   
 
    
Posts: 11
Joined: 20-Mar-2012
# Posted on: 25-Apr-2012 18:49:00   

I'm 6 weeks into prototyping LLBL and evangelizing it at my company. Now I am up against an issue that may be a deal breaker and force me to hand-roll entities and CRUD because of management's inability to see the benefits of a great tool like LLBL.

Here are the facts:

  1. I am writing WCF services that pull data from Oracle. This is Peoplesoft data, which has a ton of tables with absolutely NO referential integrity.

  2. I took advantage of LLBL to reverse engineer Oracle SP results into TypedViews. That is good.

  3. I need to take those typed views and project them into entities that model our domain, not our database. So there is, for example, a customer entity that gets loaded from data that comes from 3 separate Oracle tables. The consumer of the entity gets a nice object that is closely suits the user case. That is good.

  4. I cannot actually map this Customer entity to a physical database object -- we use web services to insert/update/delete data. There is no persistence object. This is bad.

  5. I am using the adapter pattern with the LLBL FW, and I can't even generate until I map this customer entity to some database object that will never exist. If I am taking care of persistence, why can't I have an entity that just represents a domain model?

  6. Now this is becoming an issue because management is forcing us to offer up domain entities from WCF services that are comprised of data from SQL-Server AND Oracle. A (Customer may get his SSN from Oracle, his Name from SQL). I tried adding another SQL-Server database to my LLBL project that was using Oracle, and now LLBL wants me to map my Oracle entities (entities where I had to "fake" a real Oracle database object mapping) to the SQL-Server. I was hoping I could generate one entity class library that has domain entities from both databases. I understand that I would need to DBSpecific adapter projects, but I'm taking care of persistence.

What am I doing wrong, if anything? Is there no way to have entities that aren't mapped to physical database object using the LLBL Framework? Do I have to using a DTO-only pattern (NHibernate?)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Apr-2012 06:00:25   

So your persistence comes from two DB sources and an entity could have data mixed from that two sources. But anyway you are taking care of the persistence.

LLBLGen is not designed to work in a Model-Only pattern. However you can do it:

  1. Create your entities from the LLBLGen model.
  2. Add a "Relational Model Data Storage for Database". Doesn't matter what DB you choose as you won't use this in your generated code.
  3. Auto-map all your entities: Right-click at Project root node and click "Auto map unmapped entities". This will create the needed tables/fields in your Catalog Explorer and will map your entities to them.
  4. Generate code using the Adapter template set. As you only need the model structure you can create a new preset and disable the DatabaseSpecific task group.

Now you have a ready-to-use business facade. The entities generate don't know anything about persisting (db tables, fields or mappings), so you can use them as you wish: send them to a service layer, use them in your code or generate DTO based on them, etc.

As you can see, the steps (2) and (3) are just there to make the model-only pattern works, so you won't have validation errors.

David Elizondo | LLBLGen Support Team