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 6979169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:51:07+00:00 2026-05-27T17:51:07+00:00

Trying to get a query with an anonymous type working: let temporaryBookModel = query

  • 0

Trying to get a query with an anonymous type working:

let temporaryBookModel =
  query <@ context.Books 
    |> Seq.filter (fun book -> book.Id = bookId)
    |> Seq.map(fun item -> (item.Id, item.ParentUser.Id, item.ParentUser.Alias, item.Tagline, item.Title, item.Visible, item.CreatedDate))
    |> Seq.head @>

And I keep getting:

{“Only parameterless constructors and initializers are supported in
LINQ to Entities.”}

Which would make sense if I were mapping the values to a type directly, but anonymous types shouldn’t throw this exception I would think since they are based on the object initializer functionality? Unfortunately anything I found on anonymous types seem to say this is the correct syntax. That or something like this:

let temporaryBookModel =
  query <@ context.Books 
    |> Seq.filter (fun book -> book.Id = bookId)
    |> Seq.map(fun item -> (("a", item.Id), ("b", item.ParentUser.Id), ("c", item.ParentUser.Alias), ("d", item.Tagline), ("e", item.Title, item.Visible), ("f", item.CreatedDate)))
    |> Seq.head @>
  • 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-27T17:51:07+00:00Added an answer on May 27, 2026 at 5:51 pm

    Does F# supports anonymous types?

    As I know – it doesn’t. But there are 2 possible ways for workarounds:

    • use tuples (as you’re using)
    • use record types, but in this case you’ll need to define record before. Something like this:
    type Book =
        { 
            Id: int;
            ParentId: int;
            ParentAlias: string;
            TagLine: string;
            Title: string;
            Visible: bool;
            CreatedDate: DateTime;
        }
    

    And usage code line will looks like:

    ...
    |> Seq.map 
        (fun item -> 
            {
                Id = item.Id; 
                ParentId = item.ParentUser.Id;
                ParentAlias = item.ParentUser.Alias;
                TagLine = item.Tagline;
                Title = item.Title;
                Visible = item.Visible;
                CreatedDate = item.CreatedDate
            }) 
    

    More explanations you can find in similar question here

    Update:

    Record types usage as for me is more elegant solution, BUT it looks like it doesn’t not work with Entity Framework – F# -> Record with parameterless constructor?.

    So according to Tomas Petricek answer – it has to be declared explicit type with parameters less constructor and necessary properties.

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

Sidebar

Related Questions

I'm trying to get a query working that takes the values (sometimes just the
I'm trying to get this working and the query executes but nothing comes back.
I'm trying to get the query string from a string (not the current URL).
I am trying to get my query to grab multiple rows while returning the
I am trying to get my linq query to replicate my t-sql but I
I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into
I am trying to get the below linq query to return -1 if there
I'm trying to get a queryset to issue its query over a different DB
I have this query, and I am trying to get the latest comment for
When i am trying to get query string value from URL using JQuery, It

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.