I have decided to undertake a relatively large project with F# together with MVC4 and Nhibernate.
Now, in C#, my usual practice with ORM's is the have private setters for certain properties (E.g. auto-incremented/identity properties, timestamps, etc). I.e
public class Guide
{
public int Id { get; private set; }
public DateTime Created { get; private set; }
public Guide()
{
Created = DateTime.Now;
}
}
Here id is an "identity column", and the ORM will handle setting its value.
In F# here is what I have so far
type public Guide() =
member val public Id = 0 with get, set
member val public Created = DateTime.MinValue with get, set
But the problem I have encountered is that the getters/setters cannot have access modifiers!
I am new with F#, so I would like to know the best way to perform this sort of thing. However, I do not just want to rewrite C# code in F#! I would like to know the correct (functional) approach to this. Maybe use some other construct??
Edit: For NHibernate, replace private with protected in the setters :)