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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:11:05+00:00 2026-05-27T04:11:05+00:00

Just trying to do something simple like this: context.Users.Any(fun currentUser -> currentUser.UserName = userName)

  • 0

Just trying to do something simple like this:

context.Users.Any(fun currentUser -> currentUser.UserName = userName)

Where Context is just an entity framework context. Now when I hover over “currentUser” it knows that it is a User type. However I get the:

Lookup on object of indeterminate type based on information prior to
this program point. A type annotation may be needed prior to this
program point to constrain the type of the object. This may allow the
lookup to be resolved.

Now I realize that I can do this:

context.Users.Any(fun (currentUser:User) -> currentUser.UserName = userName)

But that seems really silly since c# can easily infer type with:

context.Users.Any(currentUser => currentUser.UserName = userName)

Full method is this:

let FindAndRemoveUser(userName:String, context:StoryBoardContext) =
  if context.Users.Any(fun currentUser-> currentUser.UserName = userName) then
    let foundUser = context.Users.Where(fun innerUser -> innerUser.UserName = userName).First()
    context.Users.DeleteObject(foundUser)
    context.SaveAll() |> ignore

Am I wrong for thinking that F# should handle type inference as well or better than C#?

  • 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-27T04:11:06+00:00Added an answer on May 27, 2026 at 4:11 am

    I think that your approach has a more fundamental issue than just the problem you described. When you use Where or Any with a lambda expression in C#, the C# compiler turns the lambda into an expression tree Expression<Func<_, _>> and so LINQ to Entities can translate the code to an SQL query.

    However, when you use F# lambda function as an argument, it will be compiled as a function (or a delegate of type Func<_, _>). This means that your code will call in-memory version of the processing function and you’ll do all processing in memory instead of doing it on the database server!

    To write a query in F# 2.0, you need to wrap all code inside a quotation and run it using query function from F# PowerPack (F# 3.0 is going to make this a lot nicer, but that’s unfortunately just a beta). You probably need something like this:

    if query <@ context.Users |> Seq.exists (fun currentUser -> 
                  currentUser.UserName = userName) @> then
         let foundUser = 
           query <@ context.Users 
                    |> Seq.filter (fun usr -> usr.UserName = userName) 
                    |> Seq.head @>
         context.Users.DeleteObject(foundUser)  
         context.SaveAll() |> ignore  
    

    (Aside, I’m not sure if you need to check whether a user exists upfront – you can just find all users using just filter and then delete the first one if the returned sequence contains something)

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

Sidebar

Related Questions

Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas
Just trying to get into JQueryMobile. I want to do something simple like putting
Im trying to achieve an inner-shadow effect on a simple box, something like: alt
Just trying to get my head around Generics by reading this enlightening article by
just trying to test for equality in this piece of code, but getting a
I'm trying to do something that is fairly simple, but my code looks terrible
I'm trying to do something which should be very simple...I have a site with
I am totally new to sharepoint and just trying to get something up and
I have a pretty simple scenario and I'm sure I'm just missing something obvious.
I'm writing a simple blog-like application for Django and am trying to get 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.