Guidance on storing money values in SQLite
See original GitHub issueI am seeking some guidance for my project which will need to store money amounts in a SQLite DB from a UWP app.
From my research the .NET type of decimal is the preferred type for money. The rest of my question assumes this is correct. My model has a type
public decimal Amount { get; set; }
and as I follow the document getting started for UWP and SQLite I create a migration. I note that in the migration it appears to tell SQLite to create a column of type decimal. My migration has the following:
Amount = table.Column<decimal>(nullable:False),
From my research SQLite has no decimal type and many people appear to prefer the use of an integer and do the old */100 to find the decimal in the integer … now I am showing my age as that is an old COBOL trick.
I would love to just store the money and issue ef statements to sum the money and I should not care where ef decides to execute those statements (in SQL or client). The Utopia 😃
I am concerned that allowing ef to handle my money storage as it may not be accurate … but then getting involved and rolling my own storage seems silly if I don’t have to.
Hence here is my question on guidance?
I do not need to care as ef has me covered or I need to roll my own?
If I need to roll my own what is the consensus? Use the integer and the */100 trick within my models to expose a decimal?
Regards Chris …
Further technical details
Database Provider: SQLite: 1.1.0 Tools: 1.1.0-preview4-final Operating system: Win 10 IDE: Visual Studio 2015 patch 3
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (8 by maintainers)
I am really sorry @bricelam : this was an issue with my IDE which didn’t clear my cache and was still using the previous EF version.
…?