473,466 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Database Business Layer and Database Sync Design

Hi, until recently i was quite happy to add data sources from mssql
database in visual studio and drag the datasets directly onto the form
this creating a directly editable form which worked well.

However i have recently started a project which will require
synchronization to a remote database. Also the underlying database
provider may change at a later date. From what i have read it seems
that a layered approach is necessary, or at least recommended, where i
present an object to the form to be bound (i guess this is called the
business object in technical terms). The business object would then
communicate with a data layer which would then write to the database.

How easy is it to bind business object fields to the form? I don't
want to be hampered too much productivity wise messing with additional
coding. Will the business object controller have to return a list of
business objects? i.e. the function call in the controller layer

BusinessLayer.GetAllCustomerOrders(uint customerID), would return a
BindingList of type CustomerOrders?

Are there any standard interfaces the business object layer would use
to talk to the data layer?

Also, if i take a hit on portability to other platforms which is
unlikely at this stage, is it recommended for the business layer to
return DataSets directly? Although encapsulating a DataSet within the
business layer and presenting it as an object with fields is nice and
abstract, i can see a big time penalty. I would be prepared to return
DataSets if it would provide a happy compromise between segregation
and speed of development.

Finally, i need to synchronize the data in one database to another
database. Where would this synchronization take place? In the business
layer when a delete or addition is performed, i could (as i would be
in my Add or Delete function) perform two data access modification
calls, one to the local database and one to the remote database.

Another snag is that the databases cant be an exact synchronization as
the remote database would contain records for many users (many clients
will be adding to this hence the field IDs will not match between the
local and remote databases), would it be sensible to have a RemoteID
field in my local database row for each record? I'm thinking if that
field is empty the field hasn't been synchronized yet (the remote
database AddRecord function could return an ID which would then be
stored in the RemoteID field in the local database), when i delete a
record in the local database i will be able to delete the record in
the remote database by using the RemoteID field. Or would i base a
primary key for the table on the UserID and the local record ID? That
would indeed make a unique key but is it possible to define a primary
key with the composite of two fields? I hope that isn't too confusing
and illustrates my thoughts on howto solve this multiuser to singe
user database sync.

Thanks in advance,

Chris

May 17 '07 #1
8 4112
As a starting point you might what to take a look at Rockford Lhotka's CSLA
framework at:

http://www.lhotka.net/
<mo*****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
Hi, until recently i was quite happy to add data sources from mssql
database in visual studio and drag the datasets directly onto the form
this creating a directly editable form which worked well.

However i have recently started a project which will require
synchronization to a remote database. Also the underlying database
provider may change at a later date. From what i have read it seems
that a layered approach is necessary, or at least recommended, where i
present an object to the form to be bound (i guess this is called the
business object in technical terms). The business object would then
communicate with a data layer which would then write to the database.

How easy is it to bind business object fields to the form? I don't
want to be hampered too much productivity wise messing with additional
coding. Will the business object controller have to return a list of
business objects? i.e. the function call in the controller layer

BusinessLayer.GetAllCustomerOrders(uint customerID), would return a
BindingList of type CustomerOrders?

Are there any standard interfaces the business object layer would use
to talk to the data layer?

Also, if i take a hit on portability to other platforms which is
unlikely at this stage, is it recommended for the business layer to
return DataSets directly? Although encapsulating a DataSet within the
business layer and presenting it as an object with fields is nice and
abstract, i can see a big time penalty. I would be prepared to return
DataSets if it would provide a happy compromise between segregation
and speed of development.

Finally, i need to synchronize the data in one database to another
database. Where would this synchronization take place? In the business
layer when a delete or addition is performed, i could (as i would be
in my Add or Delete function) perform two data access modification
calls, one to the local database and one to the remote database.

Another snag is that the databases cant be an exact synchronization as
the remote database would contain records for many users (many clients
will be adding to this hence the field IDs will not match between the
local and remote databases), would it be sensible to have a RemoteID
field in my local database row for each record? I'm thinking if that
field is empty the field hasn't been synchronized yet (the remote
database AddRecord function could return an ID which would then be
stored in the RemoteID field in the local database), when i delete a
record in the local database i will be able to delete the record in
the remote database by using the RemoteID field. Or would i base a
primary key for the table on the UserID and the local record ID? That
would indeed make a unique key but is it possible to define a primary
key with the composite of two fields? I hope that isn't too confusing
and illustrates my thoughts on howto solve this multiuser to singe
user database sync.

Thanks in advance,

Chris

May 17 '07 #2
PS

<mo*****@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...

There seems to be 3 main questions you are asking.

1. Synchronization of databases
2. Transparent switching between different database providers
3. Using business objects rathers than datasets.

For the synchronization of databases I would look into resolving this issue
at the database levels rather than in your application. I have no experience
with this and there are probably som instances where your business objects
need to have some awareness that synchronization is "pending" but if you can
address this purely at a database level then it would be a cleaner solution.

The second and third questions are somewhat related as there are third party
tools/libraries that can create the core business objects for you and also
support multiple database providers and the persistence of your BOs to the
database.You can google for ORM or object relation mapping. There are
various flavors of products out there. A previous post mentions Rockford
Lhotka's CSLA framework. I have heard good things about LLBLGen.

I have added some other comments inline.
Hi, until recently i was quite happy to add data sources from mssql
database in visual studio and drag the datasets directly onto the form
this creating a directly editable form which worked well.
At the moment it would seem to be a CRUD application.
>
However i have recently started a project which will require
synchronization to a remote database. Also the underlying database
provider may change at a later date. From what i have read it seems
that a layered approach is necessary, or at least recommended, where i
present an object to the form to be bound (i guess this is called the
business object in technical terms). The business object would then
communicate with a data layer which would then write to the database.
To switch database provides you would need to abstract out the access to the
database. This would effectively be refactoring until all your database
calls were using interfaces / abstract classes. At this point you could then
use alternate concrete classes for your db access. .Net 2.0 provides
factories for DBConnection, DbCommand etc that help you with this.
>
How easy is it to bind business object fields to the form? I don't
want to be hampered too much productivity wise messing with additional
coding. Will the business object controller have to return a list of
business objects? i.e. the function call in the controller layer
If you are building them yourself then it can be a little painful. You have
to implement a lot of repetitive code to do with binding notifications. Code
generation is usually a beeter way to go, or using an ORM tool that
generates base classes for you. That is what makes DataSets attractive
initially.
>
BusinessLayer.GetAllCustomerOrders(uint customerID), would return a
BindingList of type CustomerOrders?

Are there any standard interfaces the business object layer would use
to talk to the data layer?

Also, if i take a hit on portability to other platforms which is
unlikely at this stage, is it recommended for the business layer to
return DataSets directly? Although encapsulating a DataSet within the
business layer and presenting it as an object with fields is nice and
abstract, i can see a big time penalty. I would be prepared to return
DataSets if it would provide a happy compromise between segregation
and speed of development.
Once you move away from the CRUD type application I believe that you should
move away from datasets.
>
Finally, i need to synchronize the data in one database to another
database. Where would this synchronization take place? In the business
layer when a delete or addition is performed, i could (as i would be
in my Add or Delete function) perform two data access modification
calls, one to the local database and one to the remote database.

Another snag is that the databases cant be an exact synchronization as
the remote database would contain records for many users (many clients
will be adding to this hence the field IDs will not match between the
local and remote databases), would it be sensible to have a RemoteID
field in my local database row for each record? I'm thinking if that
field is empty the field hasn't been synchronized yet (the remote
database AddRecord function could return an ID which would then be
stored in the RemoteID field in the local database), when i delete a
record in the local database i will be able to delete the record in
the remote database by using the RemoteID field. Or would i base a
primary key for the table on the UserID and the local record ID? That
would indeed make a unique key but is it possible to define a primary
key with the composite of two fields? I hope that isn't too confusing
and illustrates my thoughts on howto solve this multiuser to singe
user database sync.
Try to deal with the database synchronization at the purely database level
if possible.

PS


May 17 '07 #3
Thanks for the replies, i have a few further questions. CSLA looks very
interesting.
For the synchronization of databases I would look into resolving this
issue at the database levels rather than in your application. I have no
experience with this and there are probably som instances where your
business objects need to have some awareness that synchronization is
"pending" but if you can address this purely at a database level then it
would be a cleaner solution.
This may be the way to go as i will have a local embedded SQLite database,
and a remote MS SQL database, two different products. I guess i would need
to create a sync layer between the business object and the data layer which
would handle this synchronisation. Is it possible to form a primary key on
the composite of two fields?
The second and third questions are somewhat related as there are third
party tools/libraries that can create the core business objects for you
and also support multiple database providers and the persistence of your
BOs to the database.You can google for ORM or object relation mapping.
There are various flavors of products out there. A previous post mentions
Rockford Lhotka's CSLA framework. I have heard good things about LLBLGen.
LLBLGen is a ORM code generation tool? I'll check this out.

Cheers,

Chris

May 17 '07 #4
The second and third questions are somewhat related as there are third
party tools/libraries that can create the core business objects for you
and also support multiple database providers and the persistence of your
BOs to the database.You can google for ORM or object relation mapping.
There are various flavors of products out there. A previous post mentions
Rockford Lhotka's CSLA framework. I have heard good things about LLBLGen.
I was just looking into code generation tools to map between my database and
business objects, are there any opensource of free ones available?

What i would really like is a generation tool for Lhotka's CSLA framework as
that has some excellent features and i like the idea of portable business
objects. Any pointers to simple examples for CSLA would also be great.

Many thanks,

Chris

May 17 '07 #5
PS

"Chris" <mo*****@no.spam.gmail.remove.comwrote in message
news:A4**********************************@microsof t.com...
Thanks for the replies, i have a few further questions. CSLA looks very
interesting.
>For the synchronization of databases I would look into resolving this
issue at the database levels rather than in your application. I have no
experience with this and there are probably som instances where your
business objects need to have some awareness that synchronization is
"pending" but if you can address this purely at a database level then it
would be a cleaner solution.

This may be the way to go as i will have a local embedded SQLite database,
and a remote MS SQL database, two different products. I guess i would need
to create a sync layer between the business object and the data layer
which would handle this synchronisation. Is it possible to form a primary
key on the composite of two fields?
Also check out the Compact Edition of SQL Server . Not sure if replication
is available but at least it uses the same core database structure.
>
>The second and third questions are somewhat related as there are third
party tools/libraries that can create the core business objects for you
and also support multiple database providers and the persistence of your
BOs to the database.You can google for ORM or object relation mapping.
There are various flavors of products out there. A previous post mentions
Rockford Lhotka's CSLA framework. I have heard good things about LLBLGen.

LLBLGen is a ORM code generation tool? I'll check this out.
ORM tools sometimes generate code based off a schema, will make you inherit
a base class/interface, or will have you use attributes. Not sure which one
LLBLGen does though.
>
Cheers,

Chris

May 18 '07 #6
You're asking a lot of questions about Business Objects. I suggest that you
get one of the two books in the link, read the book, put the framework
together and put the project together to understand Business Object
concepts.

Most companies put their own frameworks together based on their needs. But
the concept of the framework and the Business Object(s) usages in various
situations will be solid for you with the CSLA concepts.

I suggest that you don't go into this blindly, but rather, know what you're
doing and why you're doing it.

http://www.lhotka.net/Article.aspx?i...b-e0059cc82ee7

May 18 '07 #7
On May 17, 12:28 pm, "Chris" <morl...@no.spam.gmail.remove.comwrote:
What i would really like is a generation tool for Lhotka's CSLA framework as
that has some excellent features and i like the idea of portable business
objects. Any pointers to simple examples for CSLA would also be great.
There are some templates (for LLBLGen actually, and others) that help
you generate Csla based classes. Check out the forums: http://forums.lhotka.net.
You'll find a very active community there.

Before you start with Csla though, you may have to shift from data
driven design to behavior based design. That's the biggest stumbling
block many that first try Csla hit. The book, Expert 2005 C# Business
objects, explains every detail of the framework, as well as explains
why you'll want to do behavior based design.

I've been building applications off of Csla for two years now, and
have nothing but praise for it. To answer one of your previous
questions, yes you can bind controls to business objects. The only
limitiation on object databinding is that you can only bind to
properties, not fields.

HTH
Andy

May 18 '07 #8
mo*****@gmail.com wrote:
However i have recently started a project which will require
synchronization to a remote database. Also the underlying database
provider may change at a later date. From what i have read it seems
that a layered approach is necessary, or at least recommended, where i
present an object to the form to be bound (i guess this is called the
business object in technical terms). The business object would then
communicate with a data layer which would then write to the database.
That is classic 3 layers.
How easy is it to bind business object fields to the form? I don't
want to be hampered too much productivity wise messing with additional
coding. Will the business object controller have to return a list of
business objects? i.e. the function call in the controller layer

BusinessLayer.GetAllCustomerOrders(uint customerID), would return a
BindingList of type CustomerOrders?
That is also very classic.
Are there any standard interfaces the business object layer would use
to talk to the data layer?
There exist a few patterns, but some of them are rather obvious:
GetOne, GetAll, Save and Delete will bring you a long way.
Also, if i take a hit on portability to other platforms which is
unlikely at this stage, is it recommended for the business layer to
return DataSets directly? Although encapsulating a DataSet within the
business layer and presenting it as an object with fields is nice and
abstract, i can see a big time penalty. I would be prepared to return
DataSets if it would provide a happy compromise between segregation
and speed of development.
DataSet are database independent.

But it is somewhat tied to databases.

List<MyDataClassread via a DataReader should be at least as
efficient as DataSet.
Finally, i need to synchronize the data in one database to another
database. Where would this synchronization take place? In the business
layer when a delete or addition is performed, i could (as i would be
in my Add or Delete function) perform two data access modification
calls, one to the local database and one to the remote database.
If the two databases are the same brand and version, then you could
consider using replication in the database tier.

If you do it in app tier, then remember to use transactions to ensure
they are indeed in synch.
Another snag is that the databases cant be an exact synchronization as
the remote database would contain records for many users (many clients
will be adding to this hence the field IDs will not match between the
local and remote databases), would it be sensible to have a RemoteID
field in my local database row for each record? I'm thinking if that
field is empty the field hasn't been synchronized yet (the remote
database AddRecord function could return an ID which would then be
stored in the RemoteID field in the local database), when i delete a
record in the local database i will be able to delete the record in
the remote database by using the RemoteID field. Or would i base a
primary key for the table on the UserID and the local record ID? That
would indeed make a unique key but is it possible to define a primary
key with the composite of two fields? I hope that isn't too confusing
and illustrates my thoughts on howto solve this multiuser to singe
user database sync.
If you use GUID's as keys, then they will be unique across all clients.

Arne
May 19 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Brett | last post by:
If I want to easily swap the database I'm using, what is the best method for developing that tier in my application? I'll have basically a 4 tier app: 1. presentation 2. business logic 3. data...
3
by: Alan | last post by:
I am coming from other programming tools field, and new to VB .NET. Just wondering what is the common approaching in database programming in VB .NET? 1) Are you guru always using the data aware...
5
by: Macca | last post by:
Hi, I have a multithreaded app which now needs database storage. I am in the process of designing my Data Access Layer but and was wondering what issues I should look for for in regards to a...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
1
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. ...
6
by: Dhananjay | last post by:
hello everyone i have got a problem i want to design business layer, data access layer , presentation layer for asp.net using C#.net , can anyone help me to solve this problem. i want some...
22
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some...
5
by: Gav | last post by:
I'm writing a windows application (using C# VS 2005 Pro) to access a MS SQL database and although it is working fine (up to now) I'm not sure I'm going about it in the best way. Can anybody point...
8
by: Charles Law | last post by:
This is a sort of pattern question, but relating to how components are coupled in a three-tier system. I have a presentation layer, business layer and data access layer, the first is the EXE,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.