it’s a kind of client-server architecture problem.
I have 2 projects in my solution: one project for the client side working with Entity Framework and SQL Server Compact database and another one for the server side also working with Entity Framework but with a real SQL Server database. Both databases have exactly the same database schema, so although they are using different .edmx files, the generated entities looks the same and only differ in namespaces. By the way I’m using the ADO.NET DbContext Generator to generate persistence ignorant entity classes. So far so good. Now I wrote a (quite large) class with all the server database access methods inside, e.g.:
public User CreateUser(string userId, string username, bool isGlobalAdmin)
{
using (var context = new ServerEntities())
{
try
{
var user = new User
{
UserID = userId,
Username = username,
IsGlobalAdmin = isGlobalAdmin
};
context.User.Add(user);
context.SaveChanges();
return user;
}
catch (Exception ex)
{
HandleEfException(ex);
}
}
return null;
}
The problem is that I need the same class with the same methods on the client side. So I would copy this class to the client project, rename ServerEntities into ClientEntities and change the namespace for using client entities. This is quite ugly, because I need to maintain both classes, if something changes. Is there a way to abstract the whole thing and use the same class (which is located in a separate prject the other two projects refer to) on both sides (client and server)?
I would really appreciate your help.
Best,
Antony
If the databases are guaranteed to be identical, why do you need both sets of entities? Just use one set so they are interoperable.