简体   繁体   English

创建表时不支持的异常

[英]Not supported exception while creating table

System.NotSupportedException: Don't know about Xamarin.Forms.Color
  at SQLite.Orm.SqlType (SQLite.TableMapping+Column p, System.Boolean storeDateTimeAsTicks) 

I got this exception while creating a database in xamarin forms. 在以xamarin形式创建数据库时遇到了此异常。 I have color property as column in my table, is this exception because of that or what causes this exception? 我的表中的列具有颜色属性,是因为该异常还是导致此异常的原因?

You cannot have a Color field in Sqlite table. Sqlite表中不能有颜色字段。 Actually only a limited data types are allowed in Sqlite database. 实际上,Sqlite数据库中仅允许使用有限的数据类型 To resolve this issue you can first convert the color object to a hex string equivalent, and then save this string to Sqlite table. 若要解决此问题,您可以首先将颜色对象转换为等效的十六进制字符串 ,然后将该字符串保存到Sqlite表中。 And finally when you want to get the saved color, you can convert back this hex string to a Xamarin.Forms Color object by this line of code: 最后,当您要获取保存的颜色时,可以通过以下代码将此十六进制字符串转换回Xamarin.Forms Color对象:

Color color = Color.FromHex(hexString);

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

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