简体   繁体   中英

DbGeography in Xamarin

I am using Entity Framework for my database. All entities are stored in a project, which is referencing Entity Framework, because some objects are having DbGeography (System.Data.Entity.Spatial) properties. Referencing this project in my Xamarin project is not possible because the System.Configuration DLL (coming from the Entity Framework reference) does not exist in Mono.

Is it possible to use DbGeography properties in Xamarin?

Edit Background Info: I have a model project, which contains only classes, which are stored in the database. This project references Entity Framework because some classes have DbGeography properties. Another project handles the database and creates contexts etc., to separate the model from the database logic. This structure is used in many projects and I access the database via a web service. One of the projects is a Xamarin app. This app should use some classes of the model project. But this is not possible because of the Entity Framework reference. I don't want to use Entity Framework in the app.

After clarifying what you're trying to accomplish, here's the (arguably) best solution for your problem.

If you've made the models yourself, extract them into a Shared/PCL library and reference it in both projects. But since you're using models residing in the Entity Framework library, you can't do that, instead:

You'll have to create identical models on your Xamarin-end, that contains similar properties as the DbGeography class does. That way, when you receive it over REST (or whatever communication you're using), convert them to your custom type instead.

Since JSON doesn't preserve any information about the original object type (per default, you can actually configure it to do that, but you actively want to avoid doing that in this case), it should be able to convert said object directly to your 'Xamarin-compatible clone of DbGeography'-class.

I'm assuming that you're using a communication method that transfers the data as JSON. But it should work for XML or similar serialization techniques as well. However if not, please specify how you're actually getting (or had hoped to) the objects between the Database and the Xamarin app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM