Reputation: 8138
The title says it. (to be clear, SQLite.NET is hosted here)
All the examples work with mutable record types, that means they have { get; set; }
in each property definition. I want to get rid of mutable types where possible in my project, but SQLite.NET looks like a possible obstacle.
If I try to get a query result with 1 column of type System.String
, it fails, for example.
So is it possible to make SQLite.NET use constructors instead of property setters, or I have to use mutable types for retrieving and storing data in SQLite.NET?
Upvotes: 5
Views: 496
Reputation: 61379
I can't say for sure if you can make SQLLite use constructors instead of properties. That said, I very much doubt it.
Using properties is much easier, as you can use reflection to find the appropriate member that matches the column name. Doing that with a constructor would be extremely painful. On that note, pretty much every other ORM works the exact same way.
If you really want to use immutable types, you'll need to put a wrapper around the ORM that takes the populated objects and returns a different object that has only immutable properties. If you really want to make sure no one ever uses the mutable types, make them internal
and put them in a separate assembly.
Granted, this is a lot of extra work just for immutable types, but given the nature of ORMs, its pretty much your only option.
Upvotes: 5