Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7493517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:00:42+00:00 2026-05-29T17:00:42+00:00

So when ever im creating some properties in my F# code , as F#

  • 0

So when ever im creating some properties in my F# code , as F# doesn’t support auto properties , as far as i know. I have to create backing fields and initialize them to null, which doesn’t seems right in functional programming terms. For e.g.


 let mutable albums : DbSet = null
 let mutable genres : DbSet = null

member x.Albums with get() = albums and set(value) = albums <- value member x.Genres with get() = genres and set (value) = genres <- value

Is there a better way of doing this ?. Many thanks for your suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:00:43+00:00Added an answer on May 29, 2026 at 5:00 pm

    F# does not support auto properties when you need a mutable property, but it supports a lightweight syntax when you need just a readonly property. If you’re writing some functional code, then using readonly properties might actually be more appropriate:

    type Music(genres : DbSet, albums : DbSet) = 
      member x.Albums = albums
      member x.Genres = genres
    

    This is essentially the same as records suggested by pad, but it may be more appropriate if you want to have better control over how the types look (and how they appear in C#, or for data-binding).

    If DbSet is a mutable type, then you probably can just use the above type and initialize it just once (you’ll still be able to modify the DbSet values). If you want to change the DbSet value, you can add a method that returns a cloned object:

      member x.WithAlbums(newAlbums) = 
        Music(genres, newAlbums)
    

    Using null or Unchecked.defaultOf<_> in F# is considered a very bad practice and you should always try to create fully initlized object. If the value may be missing, you can use option type to represent that, but then you have to always write handler for missing value, to make your program safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that doxygen uses the graphviz library for creating diagrams. Have you ever
I am creating a class that will have a Key-Value pairing of some sort.
Have you ever experienced that the Bootstrap doesn't save (with flush or without flush
I have a timer in C# which executes some code inside it's method. Inside
well i was creating a binary search tree using this code..as far as i
I am creating some buttons dynamically and assigning them IDs. When ever someone clicks
Ever since I started using .NET, I've just been creating Helper classes or Partial
Ever since the publication of Enterprise Integration Patterns people have been using the notation
Ever since I gained experience at a software house I have found it difficult
Ever since deleting the original settings.settings file I have had endless problems getting the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.