So after having watched a few of
Scott Stanfield's LINQ videos, I'm excited to get my hands dirty with some LINQ.
I want to understand best practices about how LINQ would be used in a complex application. In some of the videos, Scott shows how you can hook into the OR-generated classes for tasks such as data validation by creating a partial class and implementing a partial
method.
What are the general guidelines for adding business logic? Is it a bad idea to just extend the generated classes and add biz logic?
Or should you create separate modules as a separate layer to encapsulate the logic?
I suspect the answer is "it depends" but I'd love to hear a discussion of what y'all have learned from implementing LINQ so far.
(update: LINQPad is awesome.)
-
-
I would just go with the approaches that you already did with business objects where you didn't use LINQ at all. I suppose you had already business objects in the age before LINQ and used some of the application building blocks or design patterns. You should apply this stuff to your LINQ projects aswell.
LINQ is not something magic that turns everything upside down. It's an addition to the existing world and only transforms existing stuff into new constructs. -
Larsenal wrote:So after having watched a few of Scott Stanfield's LINQ videos, I'm excited to get my hands dirty with some LINQ.
I want to understand best practices about how LINQ would be used in a complex application. In some of the videos, Scott shows how you can hook into the OR-generated classes for tasks such as data validation by creating a partial class and implementing a partial method.
What are the general guidelines for adding business logic? Is it a bad idea to just extend the generated classes and add biz logic?
Or should you create separate modules as a separate layer to encapsulate the logic?
I suspect the answer is "it depends" but I'd love to hear a discussion of what y'all have learned from implementing LINQ so far.
(update: LINQPad is awesome.)
Yes LINQ rocks!
I am sure it will be mis-used by some folks and that will have some folks say it's bad/ wrong/ evil/ etc....
one example of using linq:
I have an app I recently finished V1 of for a win CE device, LINQ allows me to not have to use a sql database on that app.
I have a binary serializer we got from a vendor so I can store data
then I use Generics to have typed collections
and LINQ to search / query / iterate over the lists.
just a great fit and done so that 90% of the app does not know the data is just collections and serialized.
I am also using it in places where in the past I would have done the old SQL Connection / Command / Datareader / send to xxxx target with a collection / list / array/
while this is not a paragon of design I do find that it saves me a bunch of code and time and gets what amounts to the same results.
also BTW:
if you do a using (db ) { db.table.insertonsubmit(foo) db.submitchanges() }
type of block that submit will make a sql trasnaction of the updates and inserts for you so if it throws an ex you do not have a mess.
atleast with MS SQL this is true, not tested with others.
-
Key to adding business logic is realizing the power of partial classes and partial methods (lightweight events).
So in a nutshell you want to add custom code to a new source file that was not originially generated by your OR product. Also realize what hooks exist out of the box with partial methods.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.