Xamarin (IOS Android UWP) 与 SQlite 使用 OneToMany
Xamarin (IOS Android UWP) with SQlite Use OneToMany
我的设置如下。我正在 IOS Android 和 UWP 上开发跨平台 Xamarin 解决方案,除此之外我想将 SQlite 用作本地数据库。
为了在 UWP 和其他平台上使用 SQlite,我必须安装 nuget 数据包(Frank A. Krueger 的 sqlite-net-pcl)。
一切正常,但由于某些原因我无法使用属性 OneToMany。解决方案似乎是删除 SqlitePcl 包 https://forums.xamarin.com/discussion/48545/xamarin-forms-with-sqlite-one-to-many-relationship.
由于这两个限制(UWP + OneToMany),我基本上被阻止了。
有没有人遇到过同样的问题?
Everything works fine but for some reason I cant use the Attribute OneToMany.
SQLite-net PCL package created by Frank A. Krueger is recommended in the Xamarin official document Local Databases。默认情况下,此包不支持 ForeignKey
和 OneToMany
属性。如果要获取关系可以使用SQLiteConnection
的Query方法查询数据库,例如:
return db.Query<Valuation> ("select * from Valuation where StockId = ?", stock.Id);
详情请参考sqlite-net wiki.
上面的代码片段thread contains one-to-many
attrubute directly, which need the SQLite-Net Extensions package. This package provides one-to-one, one-to-many, many-to-one, many-to-many, inverse and text-blobbed relationships on top of the sqlite-net library. This package published the nuget packages 2.0.0-alpha2
to support sqlite-net-pcl to 1.2.0
according to the commit info。
因此您可能需要使用 SQLite-net PCL 1.2.0
package combine with SQLite.Net Extensions-PCL 2.0.0-alpha2
package to meet your requirements. If you need to use higher version of SQLite-net but no extension package matching you can create your own by reference the extension source code。
顺便说一句,你也可以尝试使用Entity Framework核心,它也可以设置relationships. Details please reference this article and this。
我的设置如下。我正在 IOS Android 和 UWP 上开发跨平台 Xamarin 解决方案,除此之外我想将 SQlite 用作本地数据库。
为了在 UWP 和其他平台上使用 SQlite,我必须安装 nuget 数据包(Frank A. Krueger 的 sqlite-net-pcl)。
一切正常,但由于某些原因我无法使用属性 OneToMany。解决方案似乎是删除 SqlitePcl 包 https://forums.xamarin.com/discussion/48545/xamarin-forms-with-sqlite-one-to-many-relationship.
由于这两个限制(UWP + OneToMany),我基本上被阻止了。
有没有人遇到过同样的问题?
Everything works fine but for some reason I cant use the Attribute OneToMany.
SQLite-net PCL package created by Frank A. Krueger is recommended in the Xamarin official document Local Databases。默认情况下,此包不支持 ForeignKey
和 OneToMany
属性。如果要获取关系可以使用SQLiteConnection
的Query方法查询数据库,例如:
return db.Query<Valuation> ("select * from Valuation where StockId = ?", stock.Id);
详情请参考sqlite-net wiki.
上面的代码片段thread contains one-to-many
attrubute directly, which need the SQLite-Net Extensions package. This package provides one-to-one, one-to-many, many-to-one, many-to-many, inverse and text-blobbed relationships on top of the sqlite-net library. This package published the nuget packages 2.0.0-alpha2
to support sqlite-net-pcl to 1.2.0
according to the commit info。
因此您可能需要使用 SQLite-net PCL 1.2.0
package combine with SQLite.Net Extensions-PCL 2.0.0-alpha2
package to meet your requirements. If you need to use higher version of SQLite-net but no extension package matching you can create your own by reference the extension source code。
顺便说一句,你也可以尝试使用Entity Framework核心,它也可以设置relationships. Details please reference this article and this。