473,395 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

LINQ dataContext methods - should you put business logic there?

I was just wondering, when you create dataContext methods, should you put
business logic there to try and minimize pushing data through 2-3 layers of
code? or should the business logic still go in another class somewhere
making it access the dataContext methods?

Jun 27 '08 #1
5 3790
On 13 , 23:13, "Andy B" <a_bo...@sbcglobal.netwrote:
I was just wondering, when you create dataContext methods, should you put
business logic there to try and minimize pushing data through 2-3 layers of
code? or should the business logic still go in another class somewhere
making it access the dataContext methods?
What do you mean by dataContext methods? If you mean the methods of
your DataContext class (or subclass actually), then I think that the
answer should be "no". The purpose of DataContext is to bring tables
from db and then persist your changes back to the db. And this is
exactly what the DataContext should do. Then your next tier can be
some kind of MyApplication.Services, and this is the place for your
business logic. There you'll have classes like LoginService,
CustomerService, OrderService etc., these classes will talk to
DataContext when they need. Note that these classes will be those
where you can put LINQ to SQL queries etc. I think this kind of design
is preferable, because you benefit a multi-tier architecture instead
of pushing all the stuff into one big class. And btw, in this case you
can use LINQ Designer to generate your DataContext class...
Jun 27 '08 #2
So, the linq designer in a sense, is like the dataSet designer? And linq is
sort of like a different way of making a dataSet. They are both different
things, but from what I can see so far, they sort of work the same on the
outside edges?
"Dmitry Perets" <Dm***********@gmail.comwrote in message
news:2f**********************************@m71g2000 hse.googlegroups.com...
On 13 , 23:13, "Andy B" <a_bo...@sbcglobal.netwrote:
I was just wondering, when you create dataContext methods, should you put
business logic there to try and minimize pushing data through 2-3 layers
of
code? or should the business logic still go in another class somewhere
making it access the dataContext methods?
What do you mean by dataContext methods? If you mean the methods of
your DataContext class (or subclass actually), then I think that the
answer should be "no". The purpose of DataContext is to bring tables
from db and then persist your changes back to the db. And this is
exactly what the DataContext should do. Then your next tier can be
some kind of MyApplication.Services, and this is the place for your
business logic. There you'll have classes like LoginService,
CustomerService, OrderService etc., these classes will talk to
DataContext when they need. Note that these classes will be those
where you can put LINQ to SQL queries etc. I think this kind of design
is preferable, because you benefit a multi-tier architecture instead
of pushing all the stuff into one big class. And btw, in this case you
can use LINQ Designer to generate your DataContext class...
Jun 27 '08 #3
Yes, almost. I would say, they both serve for the same purpose, but
LINQ to SQL provides more convinient and object-oriented approach. So
you don't work with DataRows and DataColumns (like you worked before),
you just work with objects. These objects can serve you in all your
tiers. And pay attention that LINQ Designer creates these objects for
you, which is not happenning with DataSets...

On Apr 14, 1:17*am, "Andy B" <a_bo...@sbcglobal.netwrote:
So, the linq designer in a sense, is like the dataSet designer? And linq is
sort of like a different way of making a dataSet. They are both different
things, but from what I can see so far, they sort of work the same on the
outside edges?

"DmitryPerets" <Dmitry.Per...@gmail.comwrote in message

news:2f**********************************@m71g2000 hse.googlegroups.com...
On 13 , 23:13, "Andy B" <a_bo...@sbcglobal.netwrote:
I was just wondering, when you create dataContext methods, should you put
business logic there to try and minimize pushing data through 2-3 layers
of
code? or should the business logic still go in another class somewhere
making it access the dataContext methods?

What do you mean by dataContext methods? If you mean the methods of
your DataContext class (or subclass actually), then I think that the
answer should be "no". The purpose of DataContext is to bring tables
from db and then persist your changes back to the db. And this is
exactly what the DataContext should do. Then your next tier can be
some kind of MyApplication.Services, and this is the place for your
business logic. There you'll have classes like LoginService,
CustomerService, OrderService etc., these classes will talk to
DataContext when they need. Note that these classes will be those
where you can put LINQ to SQL queries etc. I think this kind of design
is preferable, because you benefit a multi-tier architecture instead
of pushing all the stuff into one big class. And btw, in this case you
can use LINQ Designer to generate your DataContext class...
Jun 27 '08 #4
How do you put business logic inside of dataContext methods? When I was
reading up on them, the only thing it looked likeyou could do was to create
methods that just called stored procs on the database. Am I wrong?
"Dmitry Perets" <Dm***********@gmail.comwrote in message
news:a1**********************************@f63g2000 hsf.googlegroups.com...
Yes, almost. I would say, they both serve for the same purpose, but
LINQ to SQL provides more convinient and object-oriented approach. So
you don't work with DataRows and DataColumns (like you worked before),
you just work with objects. These objects can serve you in all your
tiers. And pay attention that LINQ Designer creates these objects for
you, which is not happenning with DataSets...

On Apr 14, 1:17 am, "Andy B" <a_bo...@sbcglobal.netwrote:
So, the linq designer in a sense, is like the dataSet designer? And linq
is
sort of like a different way of making a dataSet. They are both different
things, but from what I can see so far, they sort of work the same on the
outside edges?

"DmitryPerets" <Dmitry.Per...@gmail.comwrote in message

news:2f**********************************@m71g2000 hse.googlegroups.com...
On 13 , 23:13, "Andy B" <a_bo...@sbcglobal.netwrote:
I was just wondering, when you create dataContext methods, should you
put
business logic there to try and minimize pushing data through 2-3 layers
of
code? or should the business logic still go in another class somewhere
making it access the dataContext methods?

What do you mean by dataContext methods? If you mean the methods of
your DataContext class (or subclass actually), then I think that the
answer should be "no". The purpose of DataContext is to bring tables
from db and then persist your changes back to the db. And this is
exactly what the DataContext should do. Then your next tier can be
some kind of MyApplication.Services, and this is the place for your
business logic. There you'll have classes like LoginService,
CustomerService, OrderService etc., these classes will talk to
DataContext when they need. Note that these classes will be those
where you can put LINQ to SQL queries etc. I think this kind of design
is preferable, because you benefit a multi-tier architecture instead
of pushing all the stuff into one big class. And btw, in this case you
can use LINQ Designer to generate your DataContext class...

Jun 27 '08 #5
On Apr 15, 7:17 am, "Andy B" <a_bo...@sbcglobal.netwrote:
How do you put business logic inside of dataContext methods? When I was
reading up on them, the only thing it looked likeyou could do was to create
methods that just called stored procs on the database. Am I wrong?
Well, you shouldn't put business logic inside any methods you create
on a data context. The context's purpose is to move data in and out
of a database, nothing more. A seperate business layer should be
built, which uses the DataContext and classes created for Linq to Sql.

Check out Csla.net if you want to build business objects using a
popular business object framework.

Jun 27 '08 #6

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

Similar topics

2
by: Ronald S. Cook | last post by:
So I have a table "Employee" and wish to have a business class "Employee". This was possible before LINQ. But now that I am generating a .dbml for the LINQ DataContext, it "takes over" those names...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
2
by: Neil Chambers | last post by:
All, I have a class describing various actions to take against a LINQ to SQL datasource. What are the pros/cons of instantiating the LINQ object either in the root of the class (for lack of a...
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
1
by: Mike Gleason jr Couturier | last post by:
Hi, Is there any benefit to store a datacontext singleton in an application variable? Should I bother? Should I just create an instance of my datacontext every time my business objects...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: bob laughland | last post by:
Hi All, I am using a combination of LINQ to SQL and bulk insert. In the process of performing 'one unit of work' I will be doing things like reading, and deleting records using LINQ to SQL and...
3
by: bob laughland | last post by:
Hi All, I am using a combination of LINQ to SQL and bulk insert. In the process of performing 'one unit of work' I will be doing things like reading, and deleting records using LINQ to SQL and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.