If you are not doing something complicated, I would recommend using records instead of classes. In principle, these are classes with additional functions: immutability, structural equality, pattern matching, etc .:
type Playlists = { Albums: DbSet; Genres: DbSet }
You can easily get the record fields:
let p = {Albums = ...; Genres = ...} let albums = p.Albums let genres = p.Genres
By default, fields in records are immutable; you can declare mutable fields in records, but this is considered bad practice. Although you cannot set properties, you can create a new entry from the old one. The default continuity is usually not a problem, in addition, it makes the code more functional and understandable:
let p = {Albums = a; Genres = g} // Create new records by updating one field let p1 = {p with Albums = a1} let p2 = {p with Genres = g2}
If you insist on creating classes, it is recommended to use a constructor with explicit parameters:
type Playlists(a: DbSet, g: DbSet) = let mutable albums = a let mutable genres = g
If a default constructor is needed, you can use Unchecked.default<'T>
for fields with invalid values โโor it is better to use their default constructors:
// Set fields using dump values let mutable albums = new DbSet() let mutable genres = new DbSet()
But make sure you set these fields before actually using them.
source share