0

I am developing a C# MVC4 internet application and would like to get the data from this database and use this data in my Xamarin application.

Here is my MVC Context class:

public class DatabaseContext : DbContext
{
    public DbSet<MapLocation> MapLocations { get; set; }
    public DbSet<MapLocationCompany> MapLocationCompanies { get; set; }
    public DbSet<MapLocationDetail> MapLocationDetails { get; set; }
}

Here is my MVC connection string that I am using in the web.config:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=CanFindLocation-20140207193713;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\CanFindLocation-20140207193713.mdf" providerName="System.Data.SqlClient" />

In my Xamarin application, how can I get a DbSet for each of the DbSets in my MVC 4 Context class?

Is this possible? Can I have some advice and/or some help with this?

Thanks in advance

Garry
  • 1,251
  • 9
  • 25
  • 45

1 Answers1

0

You generally don't access your database directly from a mobile client. This is a horrible security risk.

Typically, the best approach is to create a web services layer that brokers the connection between your client and your db. The services will send json/xml data back and forth from the server to the client. The client parses the data into domain classes, possibly storing them locally in an SQLite db if necessary. Changes on the client are then updated on the server using another service call, where they are processed and updated on the server's db.

Jason
  • 86,222
  • 15
  • 131
  • 146
  • Where can I get some sample code to try the above actions described in your answer? What do you recommend I look at? – Garry Feb 10 '14 at 08:32
  • http://docs.xamarin.com/guides/cross-platform/application_fundamentals/web_services/. There are lots of documents about services in .NET, the principal is the same regardless of the client you are using. – Jason Feb 10 '14 at 16:17