Can SQLite.NET be used with immutable record types?

The name says it. (to be clear, SQLite.NET is posted here )

All examples work with mutable record types, which means that they have { get; set; } { get; set; } { 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 hurdle.

If I try to get the result of a query with 1 column of type System.String , it, for example, does not work. So is it possible to use SQLite.NET constructors instead of property constructors, or do I need to use mutable types to retrieve and store data in SQLite.NET?

+5
source share
1 answer

I canโ€™t say for sure if SQLLite constructors can be used instead of properties. However, I highly doubt it.

Using properties is much simpler because you can use reflection to find the corresponding member that matches the column name. Doing this with a constructor would be extremely painful. In this note, almost all other ORMs work in exactly the same way.

If you really want to use immutable types, you need to put a wrapper around the ORM, which picks up the filled objects and returns another object that has only immutable properties. If you really want to make sure no one is using mutable types, make them internal and put them in a separate assembly.

Of course, this is a lot of extra work only for immutable types, but given the nature of ORM, this is pretty much your only option.

+5
source

Source: https://habr.com/ru/post/1210861/


All Articles