3

I'm working on a Project to migrate a client-server application to .NET. Right now i have divided the Project in 3 layers:

* DataLayer (Entity framework) DLL
* ServiceLayer (WCF Service) DLL
* ClientLayer (WPF EXE, using MVVM pattern)

The App needs to connect to multiple database (similar structure). The databases are often changed to reflect new business requeriments).

Now my questions are:

1) Is this scenario suitable for Entity Framework (because of dealing with database changes)?

2) In this case, if i need to add a new field to say customer table, i should add the field to the database, and then update the schema on DataLayer, right? I also need to update the contracts on service layer to reflect proxy clases... and also need to modify client to change the view to obtain and send the new field to the database. So i need to re-compile all three modules for a single field added to one table?

3) Is there a best alternative on .NET for dealing with this problems, in a way that if i need to add a new field to one table i only need to re-compile client side code?

Thanks!

ericpap
  • 2,917
  • 5
  • 33
  • 52
  • If I have read the question correctly then this question is entirely to do with Entity Framework and changing database schemas - unless there is some aspect to the question that I have missed you would be better off trimming the WCF stuff out as its not relevant. – Justin Feb 23 '15 at 15:24
  • When you say "multiple database (similar structure)" do you mean that the databases have identical structures, or the databases have slight differences? If the databases have differences, it would be good to give some examples. – Justin Feb 23 '15 at 15:26
  • @Justin: I mention WCF because of the complication related to recompilation in case on database change. In the case mention (a new field add to a table) I need to recompile all three layers(correct me if i'm wrong) – ericpap Feb 23 '15 at 15:31
  • Also WCF won't support anonymous types, so i need to especify the type returned by all the methods explicit. – ericpap Feb 23 '15 at 15:32
  • The database can be sligthtly different. Tables can be the same, but A view on database A can have distinct columns on database B – ericpap Feb 23 '15 at 15:33
  • Do you know ahead of time what the differences between the databases will be, or is it possible for the database schema to change after you have deployed your WCF service? – Justin Feb 23 '15 at 15:42
  • No. It could (and it will) change after deplyment. – ericpap Feb 23 '15 at 15:45

1 Answers1

1

By far the simplest solution will be to get your EF layer to work with all of your database schemas without needing to be recompiled using views.

Build your EF layer on views in the target database. When you make changes to your database make sure that the views are updated so that they behave as they did before. This should mean that your EF layer will work against any database with those views.

Justin
  • 84,773
  • 49
  • 224
  • 367
  • Thanks for your answer, but i'm not sure i follow you. In my client i have two database A and B, with the same view (say vw_1). In DBA, vw_1 have two columns. In database B it has four. My client App needs to be able to connect to both databases. So wich DB i put on EF? A, B or both? If i put both, how can my WCF service return two different objects? – ericpap Feb 23 '15 at 16:13
  • Also if i need to add a field to say tableC on both databases, Do I need to recompile all three layers to make it work? If that's the case, this is very unflexible. – ericpap Feb 23 '15 at 16:15
  • @ericpap You need a view which is common between the two databases which doesn't change, e.g. `efvw_1`. That view should have the same schema in both databases (e.g. 2 columns), so even when you add columns to your view you don't add it to the `efvw_1` view and so the change is hidden EF and you shouldn't need to recompile your EF layer, and by extension you shouldn't need to recompile your other assemblies either. – Justin Feb 23 '15 at 16:20
  • Ok. I was afraid that's the answer. What about second question? If i add a new field to one table and need my application to take that field from user and send it to database, do I need to re-compile all three modules? Thanks! – ericpap Feb 23 '15 at 16:24
  • @ericpap You definitely need to recompile the parts of the application that need to be able to "see" that information, as otherwise how is the application supposed to act on that information? – Justin Feb 23 '15 at 16:52
  • I see. Thank you. It's obious that client need to see the new field, and need to be re-compiled. What i can't understand is why to i need to re-compile WCF layer also as it only act as a transportation method to send data between server and client. Server could also work without re-compile if it use generic method to read and save data into de database. thanks for your time. – ericpap Feb 23 '15 at 16:59
  • @ericpap If your other assemblies haven't changed then you might be able to drop just a replacement EF layer assembly [if the version number does not change](http://stackoverflow.com/questions/13751807/if-i-rebuild-a-dll-that-my-project-references-do-i-have-rebuilt-the-project). – Justin Feb 23 '15 at 17:05