Split database between Azure Mobile Service project and Asp.Net MVC project

I have two projects in one solution and I am wondering what is the ideal way to exchange the database between AMS and Asp.Net site. Also, since they both use the Entity Framework, I found it difficult to keep the models in sync across projects.

Idea 1: just let them use the same connection string; but what if I was using the first code migration to one project and the other couldn't update because its migration history is lagging behind?

Idea 2: Prevents the Asp.Net website from touching the database; let it communicate via HTTP requests with AMS; but does this add additional network overhead for communication?

Idea 3: Create a separate project containing all the entity's infrastructure classes and DbContext

and let both projects refer to it. But since the AMS project requires classes EntityData

instead of POCOs, this causes unimaginable problems to reuse model classes in another project. I just can't let the website start once I've installed all the nuget mobile packages.

Any thoughts?

+3


source to share


1 answer


just a few thoughts on your question,

Idea 1: Will get you in trouble as you suggest when you will preform the EF migration in the future. The models in each project may be different, EF won't like that. Better to avoid this solution.

Idea 3: This is what I usually use in projects that are not too heavy to use and don't have a large codebase with infrequent updates. Create a single data-tier project that contains all of the EF context and migrations, and then reference that data-tier across multiple domains or front-end layers. This works really well and can make everything easier for you. Mobile services expose database objects through RESTful APIs, so there shouldn't be too many problems there. The website must use DTOs and browse models to move data between layers. The only problem with this solution is when you update EF models in one project, you will also have to update and publish the second project as the EF models change. To get around this, I automated the build and publish process,just to make the process a little easier to manage. Think about the life of your solution, you may find yourself in a case where you project data models diverge and you get two data models in the same database. Splitting abstracts later into two databases can be very painful when you need to bring data with you.



Idea 2: In more complex cases, where I am working on a large project and constantly updating my code base and the project will last for the foreseeable future, it is best to split both services using an interface (which wonโ€™t change too often) and remove the direct dependency on the common Database. You could, as you suggest, have the data stored in AMS and then just access it via REST requests from the website. Traffic can grow and can be a problem later depending on your site and mobile service needs, which can slow down your response time to your site. Although initially, my concern would be the return time to your site from many transitions from the site to the interface of the mobile services in the db, and then back again. Although you should be able to mitigate the effects with this read data cache, you should not write data.

What I would do in your situation to simplify deployment is to combine both the website and mobile services into one solution and host the combined website and APIs together on the same Azure website using a single data layer containing EF. Therefore, do not use mobile services unless you need to, depending on the course requirements. ASP.NET can perfectly support both under one roof. This is a bit outside the scope of your question, but something that might be useful to consider for your immediate problem.

+1


source







All Articles