简体   繁体   English

Xamarin中的DbGeography

[英]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. 所有实体都存储在引用实体框架的项目中,因为某些对象具有DbGeography(System.Data.Entity.Spatial)属性。 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. 无法在Xamarin项目中引用此项目,因为Mono中不存在System.Configuration DLL(来自Entity Framework参考)。

Is it possible to use DbGeography properties in Xamarin? 是否可以在Xamarin中使用DbGeography属性?

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. 该项目引用了Entity Framework,因为某些类具有DbGeography属性。 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. 在许多项目中都使用此结构,我通过Web服务访问数据库。 One of the projects is a Xamarin app. 其中一个项目是Xamarin应用程序。 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. 如果您是自己制作模型的,请将其提取到Shared / PCL库中,并在两个项目中都进行引用。 But since you're using models residing in the Entity Framework library, you can't do that, instead: 但是,由于您使用的是驻留在Entity Framework库中的模型,因此不能这样做,而是:

You'll have to create identical models on your Xamarin-end, that contains similar properties as the DbGeography class does. 您必须在Xamarin端创建相同的模型,该模型包含与DbGeography类相似的属性。 That way, when you receive it over REST (or whatever communication you're using), convert them to your custom type instead. 这样,当您通过REST(或正在使用的任何通信)接收到它时,请将它们转换为您的自定义类型。

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. 由于JSON不会保留有关原始对象类型的任何信息(默认情况下,您实际上可以对其进行配置,但是在这种情况下您要积极避免这样做),因此它应该能够将所述对象直接转换为您的对象“与Xamarin兼容的DbGeography克隆”类。

I'm assuming that you're using a communication method that transfers the data as JSON. 我假设您正在使用一种将数据作为JSON传输的通信方法。 But it should work for XML or similar serialization techniques as well. 但它也应适用于XML或类似的序列化技术。 However if not, please specify how you're actually getting (or had hoped to) the objects between the Database and the Xamarin app 但是,如果没有,请指定您实际上是如何(或希望)获得数据库和Xamarin应用程序之间的对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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