Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Replace Deprecated Type Provider with Entity Framework Core in Query Expressions Documentation

The type provider example in F# query expressions documentation is using deprecated FSharp.Data.TypeProviders which is not compatible with modern .NET versions (net5.0+). This PR replaces it with Entity Framework Core, which demonstrates real database querying - the intended purpose of F# query expressions.

Changes Made

1. Project Structure

  • Fixed fssamples.fsproj to use correct SDK (Microsoft.NET.Sdk)
  • Removed redundant /samples/snippets/fsharp/query-expressions/query-expressions.fsproj
  • Integrated query-expressions files into parent project targeting .NET 9.0
  • Added Entity Framework Core package references:
    • Microsoft.EntityFrameworkCore (9.0.0)
    • Microsoft.EntityFrameworkCore.InMemory (9.0.0)

2. Entity Framework Core Implementation

  • Replaced deprecated SqlDataConnection type provider with proper EF Core DbContext classes
  • Implemented SchoolContext and NorthwindContext using EF Core patterns
  • Created entity types (Student, Course, CourseSelection) with [<CLIMutable>] attribute
  • Used Nullable<T> for nullable fields (standard EF Core pattern)
  • DbSet properties provide the familiar db.Student, db.Course, db.CourseSelection pattern
  • Used EF Core in-memory database provider for examples (can be swapped for SQL Server, PostgreSQL, etc.)
  • Properly seeded database with sample data

3. Documentation Updates

  • Updated query-expressions.md to use :::code language="fsharp" source="..."::: syntax for external snippets
  • Fixed document date to 09/26/2025
  • Updated text to explain Entity Framework Core usage
  • Added notes about package requirements and provider options
  • Explained that in-memory provider is for demonstration but works with any EF Core provider
  • Maintained original db.Student syntax throughout (no unnecessary renaming)
  • Removed deprecated assembly references and old F# Interactive output
  • Added AI usage disclosure

4. Why Entity Framework Core?

Query expressions in F# are designed for querying databases (RDBMS), not in-memory collections. F# already has strong combinators (List, Array, Seq modules) for in-memory data. The original examples with deprecated type providers correctly demonstrated database querying; this PR modernizes that approach using EF Core, which is:

  • The standard for .NET database access
  • Supported on modern .NET (5.0+)
  • Shows real-world patterns developers will use
  • Works with all major database providers

Testing & Validation

  • ✅ Project builds successfully with EF Core dependencies
  • ✅ Query expressions work correctly with EF Core DbContext
  • ✅ Examples demonstrate actual database patterns
  • ✅ Code is idiomatic F# with EF Core
  • ✅ All query operators function correctly
  • ✅ Familiar db.Student pattern matches EF Core usage

Impact

  • Developers can now use the query expressions documentation with modern .NET (5.0+ including .NET 9.0)
  • Examples demonstrate real database querying - the actual purpose of F# query expressions
  • Uses Entity Framework Core, the modern standard for .NET database access
  • No more dependency on deprecated type providers
  • Patterns shown are what developers will actually use in production
  • Documentation follows current Microsoft Docs formatting standards

Fixes #22206

Original prompt

This section details on the original issue you should resolve

<issue_title>Type provider example does not seem to work</issue_title>
<issue_description>
Type provider example does not seem to work. It seems to be not compatible with target net5.0.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Comments on the Issue (you are @copilot in this section)

@BillWagner To fix this, let's start by moving the snippets into an F# project and then update the code to ensure it compiles against .NET 9
Fixes #22206

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/fsharp/language-reference/query-expressions.md docs/fsharp/language-reference/query-expressions

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Sep 25, 2025
@Copilot Copilot AI changed the title [WIP] Type provider example does not seem to work Fix deprecated type provider example in F# query expressions documentation Sep 25, 2025
@Copilot Copilot AI requested a review from BillWagner September 25, 2025 15:13
Copilot finished work on behalf of BillWagner September 25, 2025 15:13
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot You need to fix the build errors.

Copy link
Contributor Author

Copilot AI commented Sep 26, 2025

@copilot You need to fix the build errors.

Fixed the build errors by removing the redundant query-expressions.fsproj and integrating all files into the parent fssamples.fsproj. The project now builds successfully without any errors. Commit: 9627b65

@Copilot Copilot AI requested a review from BillWagner September 26, 2025 15:14
Copilot finished work on behalf of BillWagner September 26, 2025 15:14
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things to address here @copilot

@Copilot Copilot AI requested a review from BillWagner September 26, 2025 18:35
Copilot finished work on behalf of BillWagner September 26, 2025 18:35
@BillWagner BillWagner requested a review from T-Gro September 26, 2025 18:48
@BillWagner
Copy link
Member

Tagging @T-Gro for review, even in draft status.

Is the new sample idiomatic F#? It looks more like C# translated to F#, but in this area, they can be quite similar.

@T-Gro
Copy link
Member

T-Gro commented Oct 3, 2025

@copilot :

I disagree with the motivation.
If anyone is going to use queries (if) in F#, it will be for RDMBS data.

The example should show that.

F# has strong combinators for in-memory data (List,Array,Seq,..) and there is no added value in using queries for that.

THe original set of samples usign db.Student was real-world-like and actually showed how to query a database - this is what the language feature is for.

@Copilot Copilot AI requested a review from T-Gro October 3, 2025 06:41
Copilot finished work on behalf of T-Gro October 3, 2025 06:41
Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot :

I disagree with the motivation.
...

I understand your concern. The original examples with SqlDataConnection type provider showed real database queries, but that type provider is deprecated and doesn't work with modern .NET (net5.0+), which was the original issue.

What would you prefer for a modern alternative that maintains the database context? Options could be:

  1. Use EF Core with F# to show actual database queries
  2. Keep the conceptual db.Student pattern but explain it's illustrative of database usage
  3. Revert to the original broken example with a note that it's deprecated

Which approach would best serve developers learning F# query expressions?

Copilot finished work on behalf of T-Gro October 3, 2025 06:43
@T-Gro
Copy link
Member

T-Gro commented Oct 3, 2025

@copilot : Use EFCore

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot : Use EFCore

Implemented Entity Framework Core examples as requested. The snippets now use proper DbContext classes with EF Core 9.0, demonstrating real database querying patterns. The examples use the in-memory database provider for demonstration purposes, but the same query syntax works with any EF Core provider (SQL Server, PostgreSQL, etc.). This properly shows the purpose of F# query expressions - querying databases, not in-memory collections. Commit: d1680c7

@Copilot Copilot AI changed the title Fix deprecated type provider example in F# query expressions documentation Replace deprecated type provider with Entity Framework Core in F# query expressions documentation Oct 3, 2025
Copilot finished work on behalf of T-Gro October 3, 2025 07:08
@BillWagner BillWagner marked this pull request as ready for review October 3, 2025 14:36
@BillWagner BillWagner requested review from a team as code owners October 3, 2025 14:36
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM now as well.

Thanks @T-Gro

@BillWagner BillWagner merged commit 0de9e89 into main Oct 3, 2025
18 checks passed
@BillWagner BillWagner deleted the copilot/fix-8d3b8449-7db6-402f-ba9d-56658004b86e branch October 3, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fsharp/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type provider example does not seem to work
3 participants