views:

32

answers:

2

Hi guys,

I seem to be having trouble splitting a namespace across projects.

I have a DatabaseAccess project which has a folder called SCS (Some Crazy System) which provides data access to the database for SCS. Now this SCS has entity framework (.edmx) generated entities. I would like to extend these entities in my BusinessModel project. However I don't seem to be able to do so. below is my example. I am creating a partial class and also creating a namespace with the same name as the namespace in my actual DatabaseAccess project:

namespace DatabaseAccess.SCS{
    public partial SomeEntity{
         public void DoSomething(){
             var x = this.GeneratedField;
         }
    }
}

Doing the above doesn't work. It complains that GeneratedField is not part of the SomeEntity class even though it is. If i pop open the SCS.Designer for the edmx, SomeEntity indeed does have a definition for the GeneratedField and SomeEntity is part of the DatabaseAccess.SCS namespace. What gives?

+1  A: 

You're not just splitting the namespace across multiple projects there, but the class too. I doubt that's possible as it would usually be very difficult to construct such objects as each object usually has heavy dependencies on... well, itself! (Extension methods could though provide similar functionality - although I don't recommend overusing them. Neither does the documentation.)

Why don't you just have that partial in the same project as the other part of it?

steinar
you're right. i've decided to just put the partial in the same project. it's better that way architecturally as well.
A: 

If the partial class isn't in the same project, you'll have to add a reference to the assembly built from the other project. Otherwise the local project doesn't already know the class in order to extend it.

Erik Noren