1

(I feel like I'm missing something important here.)

I'm creating a WCF Data Service (5.0) using the "database first" approach for the entities.

I've created tables with "namespaced" names, using the . (dot) such as [Entertainment.Event] and [Promotions.Event].

The EF 4.x POCO generator template of course knocks these out, via the call to CSharpCodeProvider.CreateEscapedIdentifier().

I'd like very much to generate (and regenerate, and appropriately map) namespaced POCOs; specifically, preserving the implied namespaces of the tables.

What am I looking at as far as accomplishing this? I'm guessing it will involve awhile's worth of swimming through T4 templates.

Ultimately, is this doable?

Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
  • I don't see how that would work - the properties of the context that represent the tables would be `DataContext.Entertainment.Events`, `Datacontext.Promotions.Events`, etc. which would be invalid. – D Stanley Nov 26 '12 at 20:28
  • @DStanley Yes, you are right. I suppose this would necessitate an additional context per namespace as suggested below, or some sort of aliasing. I'm guessing I'll have to explore multiple contexts. – Dan Lugg Nov 26 '12 at 20:46
  • @DStanley Alternatively, this specific issue could be handled in the template; building a list of potential property names, and namespace qualifying pairs (*or more*) of collisions prior to generation. Thus, `EntertainmentEvents` and `PromotionsEvents` would be the context's properties, but related entities would merely have `Events` (*provided they didn't also reference both event types*) – Dan Lugg Nov 26 '12 at 21:30

1 Answers1

2

I'd suggest to create one context per your DB schema, placing each one into whatever namespace you like.

Serge Belov
  • 5,633
  • 1
  • 31
  • 40
  • Thanks @SergeBelov, however, what about relationships between entities in different contexts? Following my example tables; an `Entertainment.Event` and a `Promotions.Event` may each occur at the same `Location` – Dan Lugg Nov 26 '12 at 20:41
  • @Bracketworks There has been a good discussion about that here: http://stackoverflow.com/questions/158986/how-to-relate-objects-from-multiple-contexts-using-the-entity-framework – Serge Belov Nov 26 '12 at 20:55
  • Thanks @SergeBelov. I guess I have some reading to do, and remodeling considerations to make; my understanding of EF is less than complete, however this seems to have been made more complicated than necessary. – Dan Lugg Nov 26 '12 at 21:24