0

I'm trying to implement a client-server solution with MonoTouch + Mono for Android.

For the server side, I'm using an ADO.NET entity model. AFAIK, this is not a part of the above frameworks, but my question is:

Can I reference a (common) ADO.NET/EF4-based data layer project in the client only for the sake of partially reusing the entities on the client side? Alternatively, is there a different solution for this architectural issue?

EDIT: Forgot to say, for the client side, I'm thinking about POCO entities, automatically generated from the POCO template.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ury
  • 1,050
  • 11
  • 22
  • If you want to reference the entities, I would remove them from the data layer project and put them into their own, separate class library (free of any datalayer technology - just the classes). That way, I'm sure you can share that assembly! – marc_s Aug 26 '12 at 09:28
  • 2
    Found the solution [here][1], hopefully it can help others too. [1]: http://stackoverflow.com/questions/2464909/generate-poco-classes-in-different-project-to-the-project-with-entity-framework – ury Aug 26 '12 at 10:21

1 Answers1

1

A good way to do such a thing is by going for the Code-first approach in ADO.NET entity framework. After you have created the entities on the server and built a DataContext implementation for them, follow these steps to add entities to your Mono for Android project (If you're using Visual Studio that is).

  1. Right click the Mono for android project and select Add Existing item
  2. Select the files you want to add
  3. Click the small Arrow next to the Open button and choose Link.

Now when you edit the files in the server project or the client, they will stay in sync. Keep in mind that the set of attributes and API's you can use from the entities is limited. It may take a bit of fiddeling to get things right.

Tip: Use partial classes for adding environment specific behavior and data. Add a second .cs file for each entity class and add any members that you don't want on the client to that file. The same works for client features you only want in your app, but not on the server.

All of the above also works when you work on a mac with MonoDevelop. That application also supports linking items that are on a different location from the .csproj file location.

Willem Meints
  • 1,152
  • 14
  • 33