473,549 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3808
On 13 ÁÐÒ, 23:13, "Andy B" <a_bo...@sbcglo bal.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.S ervices, 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******** *************** ***********@m71 g2000hse.google groups.com...
On 13 ÁÐÒ, 23:13, "Andy B" <a_bo...@sbcglo bal.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.S ervices, 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...@sbcglo bal.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?

"DmitryPere ts" <Dmitry.Per...@ gmail.comwrote in message

news:2f******** *************** ***********@m71 g2000hse.google groups.com...
On 13 ÁÐÒ, 23:13, "Andy B" <a_bo...@sbcglo bal.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.S ervices, 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******** *************** ***********@f63 g2000hsf.google groups.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...@sbcglo bal.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?

"DmitryPere ts" <Dmitry.Per...@ gmail.comwrote in message

news:2f******** *************** ***********@m71 g2000hse.google groups.com...
On 13 ÁÐÒ, 23:13, "Andy B" <a_bo...@sbcglo bal.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.S ervices, 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...@sbcglo bal.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
1133
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 for its classes. I'd hate to have to name my business classes "EmployeeClass" or some other non-ideal convention. Any thoughts? Thanks,
0
2350
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 occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the...
4
2175
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 not reinsert it with a different revision number. Compounding the issue, we’ve also got an associated table storing properties for our entities...
2
1726
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 better description) or within each of the methods? I am naturally drawn to instantiating the LINQ object in the root but some examples I've seen...
21
4333
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
1
2619
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 need it?
3
12421
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: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean...
0
4389
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 then inserting new records using bulk insert. One problem I am having is trying to use a 'transaction' to wrap around the whole thing.
3
10898
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 then inserting new records using bulk insert. One problem I am having is trying to use a 'transaction' to wrap around the whole thing.
0
7532
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7462
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3510
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.