Reputation: 835
I'm using MobileServiceSQLiteStore
(offline sync) for my Azure Mobile App.
I've noticed that data/columns I've typed as decimal
are getting stored in the local SQLite database as float
What's the correct approach for ensuring the correct type?
Upvotes: 0
Views: 77
Reputation: 18465
As the DefineTable
method under MobileServiceSQLiteStore.cs, it would use the following code to retrieve the local table definition as follows:
var tableDefinition = (from property in item.Properties()
let storeType = SqlHelpers.GetStoreType(property.Value.Type, allowNull: false)
select new ColumnDefinition(property.Name, property.Value.Type, storeType))
.ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);
The GetStoreType
method under SqlHelpers.cs would convert the store type based on the JToken type. I have checked and found that both the column types (double
, float
, decimal
) you defined in the model would be converted to ColumnType.Float
.
As Datatypes In SQLite described:
SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statements that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases.
Per my understanding, you could declare a specific data type for your column when you create a table, and you could store any kind of data types into this column. And based on my test, I could insert/retrieve my item correctly. I assume that you could just ignore this issue or you could try to override the MobileServiceSQLiteStore
for achieving your purpose.
Upvotes: 0