Im a newbie struggling to get it right - pls be gentle!

Posts   
 
    
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 03-Nov-2004 10:45:57   

Hi,

I apologise right now, both for my long ramblings (perhaps there should be a prize for the longest post!?!), and for any stupid questions that I ask. However after scouring the help files and the forums I am still slightly unclear as to the best approach I should adopt, or even if what I hope to achieve is possible.

Let me put you in the picture (are you sitting comfortably – then I shall begin). I am a self taught developer with 12 years of professional experience. My knowledge of VB.NET is above average, however being self taught I guess I have never really learnt how to do things properly – I come from a background of RAD developments and “quick fixes”. I do understand the basic concepts of OO programming but I guess if I am honest I don’t make the best use of the technology.

I have reached a point whereby it is time to do things properly and get rid of all my bad habits. So I have made the decision to use C# from now on and also start developing applications using true n-tier technology – I love a challenge!

THE PAST

A couple of years ago I developed a commercial application in VB.NET, and based on my knowledge at the time, this application is made up of various windows forms that have all the logic and database SQL statements embedded in them. Each of the forms is therefore a small black box.

There is then a common menu system that sits inside an MDI container form that uses reflection to open the relevant window form as a child form to the MDI container. This approach works fine and I am successfully supporting the application today. If I need to add functionality, I simply create a new form add all the logic required and make sure that the menu system knows that this new form exists.

However, I know this is not an ideal approach and this is not the way I want to continue. Therefore, more recently, I have developed applications whereby

  1. I have a whole series of stored procedures to do the database stuff.
  2. I have a class for each entity that knows which stored procedure to run for each of the main actions, add, update, delete etc.
  3. I have other methods within each entity class for validation, returning data-tables etc
  4. I have a library of standard windows components that make it easy for me to put together basic administration forms for the entities (add, modify, delete)

THE PRESENT

As you can guess, there is a whole load of boring repetitive tasks in adopting this approach and it was at this point that I came across LLBLGen Pro.

What I like about LLBLGen Pro are two things 1. It does all the boring stuff for me 2. The entity classes that it generates are FAR more sophisticated than anything I could ever put together myself.

THE FUTURE

From the examples etc I can see that LLBLGen will save me loads of time if I wanted to continue placing business logic in the presentation layer, and it will make my code much more compact and easy to follow.

However I am keen to use a business logic layer to hold all of the logic because in the application that I am developing 1. I want to make the BL available to business partners/clients so that they can build their own interfaces. Therefore I don’t want them to have the full power of the LLBL classes, I want to restrict the methods/properties that they have available to them 2. I want to be able to use the same logic for both web and windows front ends to my application.

With this in mind…

I will be using the adapter C# template to generate my Data Layer, so using Northwind, for example I will have

Northwind.Engine.Data Northwind.Engine.DataDBSpecific

As my 2 LLBL generated libraries.

On top of these I would need to have a library that deals with the database connection string because I hold the connection string details in an XML configuration file. However I don’t want anyone reading the XML file to see the username and password, so these are held in the XML file in an encrypted format. The database connection library will contain everything it needs to return the connection string from the encrypted values held in the XML file.

Northwind.Engine.DBConnection

Finally I would like to have a library of my business logic

Northwind.Business.Entity

It is this library that contains all of the entities that my presentation layer will use. The presentation layer will NOT access the Northwind.Engine… libraries directly.

The presentation layer will consist of a number of libraries, some holding components, and some holding forms. My application will still have a menu system inside an MDI container form that uses reflection to run the relevant PL class from the relevant PL library.

NOW DOWN TO THE ISSUES

How can I best achieve my aims so that:

The Northwind.Business.Entity library contains all of the functionality that my PL requires regarding both entities and collections – I will be using collections to databind to grids.

Users of the Northwind.Business.Entity library only have access to specific functionality that I want them to have, so for example the Order entity might have properties for each of the database fields and only the following methods available to users. FetchOrder(int id) Save (handles both new and updates) Delete FetchRelatedOrderLineCollection FetchRelatedCustomer

In terms of collections, I still want to use a single EntityCollection (as per LLBL adapter templates) but how do I make the LLBL EntityCollection available to my PL WITHOUT referencing the LLBL generated classes into my PL (or do I have no choice)

Also in terms of collections, will the EntityCollection be holding a collection of my objects stored in the Northwind.Business.Entity library or will it hold a collection of the underlying LLBLGen entities – thus causing me a problem because the underlying objects have much more functionality than I require.

I have read elsewhere in the forum that people are using datatables as opposed to collections for databinding to grids… is this something that is going to make my life easier… how do I turn an LLBL collection into a datatable?

I could keep going, but as you can see “I don’t get it yet”. Any help on these issues would be much appreciated, and I am sure I will be back for more once I digest any replies people kindly supply.

Huw

netLearner
User
Posts: 150
Joined: 18-Oct-2003
# Posted on: 03-Nov-2004 12:32:13   

Create an intermediate layer between your UI and BusinessEngine. For argument sake call it UIBusiness, in here create a class called Orders. Add the 5 methods you wanted to be exposed to your clients. Add an instance variable called dataObject which is private and holds to the collection/entity. When you call the any of the methods you exposed, get the dataObject pass the message to it and get the data and return it. Hope it makes sense. Thanks.

hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 03-Nov-2004 14:00:44   

Thanks for the reply, I think it has helped me a great deal…

If I understand what you are saying,

1.In my Business Logic library, Northwind.Business.Entity, I create a brand new empty class called Order which does not inherit from any of the LLBL classes.

2.I create a private member variable mLLBLOrder of type OrderEntity {The LLBL generated class}

OrderEntity mLLBLOrder;

3.In the Contructor method of the Order Class I create a new OrderEntity

public Order 
    {
        mLLBLOrder = new OrderEntity();
    }
  1. I add properties for each of the database fields for an order that get or set the underlying mLLBLOrder properties
public int OrderID
    {
        get
        {
            return mLLBLOrder.OrderID;
        }
        set
        {
            mLLBLOrder.OrderID = value;
        }
    }
  1. I add the methods I want that all use the underlying mLLBLOrder
public void save()
    {
        mLLBLOrder.Save()
    }
public EntityCollection FetchRelatedOrderLineCollection()
    {
        ...
        {returns a LLBL generated Entity Collection}
    }
etc

If this is the case then I think I am getting there.... Just one simple question, the return type of my FetchRelatedOrderLineCollection() method above is an EntityCollection created by LLBL. Will I be able to use this as the datasource of a grid in my PL as shown:

Order myOrder = new Order(23)
    grid.Datasource = myOrder.FetchRelatedOrderLineCollection()

OR, will i need to reference the LLBL generated libraries into the PL so that they know what an EntityCollection object is? - How could I set the datasource of the grid to the EntityCollection without the PL knowing that LLBL exists.

Thanks for all the help it is really useful

Huw

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 04-Nov-2004 15:55:26   

You asked "How could I set the datasource of the grid to the EntityCollection without the PL knowing that LLBL exists."

Just turn the collection into a dataset before you return it.

There has been some debate about wheter or not to have your UI reference the LLBLGen ORM Libraries and the assemblies that are created as a result of code gen. Here is my take on that:

I develop a services layer for everything, i.e. I have controller classes that expose all of my functionality for CRUD operations. For applications that my company develops, we see no harm in our clients (be it web or windows) referencing the LLBLGen ORM objects and the code generated assemblies.

However, in the event that we need to expose an object over remoting, or XML Web Services for those that want to use our SDK to create their own interfaces, they get a watered down wrapper for our services layer.

wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 04-Nov-2004 16:04:31   

Some cool links to old, old threats

  1. Passing Entities accross tiers - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=802
  2. Collections in the business layer - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=811
  3. Passing Collections or DataTables - http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=834
hplloyd
User
Posts: 191
Joined: 29-Oct-2004
# Posted on: 05-Nov-2004 16:36:13   

Thanks everyone,

It is now much clearer.

Huw