views:

215

answers:

3

Are the classes generated by LINQ (DBML) considered POCOs? If I add static queries to these classes, are they still POCOs?

I imagine it changes once I start doing business things in the LINQ partials. Such as adding other attributes, creating collections and basically making the partials more than DAL classes.

If the LINQ classes are POCOs, what is another example?

A: 

I would say not. There is a decent amount of intelligence in a Linq to SQL designer-generated class.

Dave Markle
A: 

Well, they don't inherit any special base class at least. And most of the code there you can simply remove -- LINQ-to-SQL doesn't need any of it. But note that in doing so, you'll lose out on a lot of enhancements such as more efficient change tracking (no property changed events) and deferred loading for relationships.

More importantly, who cares if someone considers them POCO if they work for what you need? As far as adding your own behaviour onto the data object... that's what objects are for. POCO doesn't mean no behaviour, it just means the objects aren't too "wierd" or with lots of framework-specific code (such as special base class needed, special interfaces, etc.)

MichaelGG
A: 

The short answer is no. The classes generated by LINQ to SQL contain database persistence logic, which is required by LINQ to SQL in order for it to work properly. POCOs, by definition, do not have such code.

Eric King
I'm still unclear on what a POCO is. It's such a subjective meaning as to be meaningless. What is a real world example of a POCO?
4thSpace
My definition is: an object based on a class that only knows and cares about itself. It contains members, properties, and methods that don't depend on external entities. Once it deals with external dependencies (a persistence framework or logging mechanism, for example), it's no longer a POCO.
Eric King
It sounds like utility class. Something business logic independent. But still, what is a real world example?
4thSpace
In other words, a Person object would be a POCO if it contained properties such as FirstName and LastName and DateOfBirth and simple self-contained methods such as GetAge() and GetFullName(). When a method like SaveToDB() is added, it's now dependent on external infrastructure and isn't a POCO.
Eric King
Thanks. So if this were an MVC, these would live in the model just above the DAL? What if GetAge() calculates age in real time? What if it has a property named AddressHistory of type List<Address> that lazily retrieves addresses from the DB?
4thSpace
Whether and how to use POCOs is the subject of much debate... But in general, yes, POCOs are usually used in the domain model just above the DAL (Repository maybe?). There's also many different opinions about how a POCO should be allowed to lazy-load children and still be considered a POCO.
Eric King
Ok. Is this really a useful term than if it has no clear definition? Meaning, each person you talk to will have their own meaning/interpretation of POCO. Thanks again.
4thSpace
Well, it's probably just as useful as most other terms out there. You're just as likely to find varying definitions of 'DAL' and 'lazy-load' and 'repository' and 'object-oriented'. Very few terms in this industry have iron-clad "clear" definitions, yet somehow we still manage to communicate ...
Eric King