Partial Class and Namespaces

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have the following namespaces:

Domain
Domain.Repositories
Domain.Entities
Domain.Models
Domain.Services

In Domain.Entities I have partial class Context:
public partial class Context : global::ObjectContext {
// Entity Framework code
}

To implement UnitOfWork pattern I created the following class:

namespace Domain {
public partial class Context : ObjectContext, ISession {
public void Commit() {
SaveChanges();
}
public void Rollback() {
Dispose();
}
} // Context
}

This only works if I move this to namespace Domain.Entities or I get
the error:
'System.Data.Objects.ObjectContext' does not contain a constructor
that takes '0' arguments

The reason why I would like to have this in Domain would be to be able
to name my Models and Entities the same way. So I would have:

Entities.Post and Models.Post.

Only in services I would need to write Entities.Post and Models.Post.

On the repositories I only need the Entities so I need to write only
Post referring to Entities.Post

And on the presentation layer I don't need the entities so I can write
also only Post referring to Models.Post.

The problem is that on presentation I need to use the Context ...

Probably I am looking at this the wrong way and I should just name the
models something else like:
PostUI ... It does not sound very good because this would be used not
only by the Presentation layer but also by the Application layer.

Anyway, could someone advice me on this?

Thank You,
Miguel
 
[...]
Probably I am looking at this the wrong way and I should just name the
models something else like:
PostUI ... It does not sound very good because this would be used not
only by the Presentation layer but also by the Application layer.

Anyway, could someone advice me on this?

The name of your "Post" class isn't the problem here. It's that you're
trying to put the two partial pieces of the "Context" class in two
different namespaces.

You need to figure out what namespace the "Context" class belongs in, and
then put all of the declarations for "Context" into that namespace.

Pete
 
Back
Top