views:

114

answers:

2

I have a .dbml file which of course contains the auto-generated classes based on my tables.

I would however, like to extend them to my own classes. Typically I design such that each of my tables get their own namespace in their own folder containing all of their associated dao and service classes. So if I am dealing with a page that only has to do with 'customers' for instance, I can only include the customerNS.

But when using LINQ I seem to be unable to do this. I have tried removing a default namespace from the project, I have tried putting the .dbml file into it's own folder with a custom namespace and then adding a 'using' statement, but no nothing works.

I also saw the Entity Namespace, Context Namespace, and Custom Tool Namespace properties associated with the .dbml file and tried setting all these to names x and trying 'using x' in my other class to allow me to extend partial classes, but it just doesn't work.

Is this possible or do I have to keep all extended partial classes in the same namespace as the .dbml file?

A: 

You have to keep all linq classes in one namespace. Why you trying to put DO classes in different namespaces?

vittore
LINQ's generates classes save time, but they aren't how I organize my projects at all. As I said I usually have one object per namespace using a sorta SOA approach. Each namespace has it's respective object class as well as DAO and service classes. Then on the front-end when I am working with a page that only deals with one or two tables (which correlate to the objects), I only put usings for those and my intellisense isn't super cluttered and it's more effecient.
sah302
i think it is not very convenient, i'd rather have DAL.DataObjects namespace, DAL.DataManager namespaces, etc; but probably that's a taste choose. However having all DO objects in one namespace and separate assebly , not with services will allow you for instance reference this assembly from different tiers of your N tiered application. For instance consider `DO` assembly referenced by `DAL` and `BLL` assemblies
vittore
Interesting point you bring up, though I am not sure I would ever run into that issue for my work (our needs are fairly simple hehe). Thank you for your reply.
sah302
A: 

If the types don't have relations the answer is simple: use multiple dmbl files. If you need relations and you also want multiple namespaces read on.

You might be able to get this done with a T4 template file. In VS2010 there's a template to create one (it's called a generator template or something). For VS2008 you can find one on codeplex

The changes you'll need to make to the standard template is you need to make sure that all properties use fully qualified names (because the related types are now in different namespaces). And for most control you can probably skip the namespace info from the generated classes (so you can define it in your partial classes).

Sander Rijken
I am curious do you know what the Entity Namespace property is when you open up the .dbml in designer view? It says "Specifies the namespace of the generated entity classes." It seems like that would allow me do what I want, but it doesn't seem to have any affect on anything.
sah302
@sah302: that is namespace for all entity classes not namespaces for each of them.@Sander Rijken: T4 - good catch, of course it could help. But in particular situation I'd rather suggest to consider different stratagy for placing classes inside namespaces
vittore
Yes thanks, I just got it working like that but it's still limited to only one namespace. Thank you for your replies!
sah302