Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Shawn_Eary
Advocate IV
Advocate IV

Is EntityFramework Code First Supported in Fabric SQL Database?

I have an empty SQL database in Fabric. Grok wrote a few POCOs and created a DBContext for me. Grok then told me to do this:
dotnet ef migrations add InitialCreate

That run okay with this warning:
PS C:\Users\seary\source\repos\UITS-seary-language-helper> dotnet ef migrations add InitialCreate
Build started...
Build succeeded.
The Entity Framework tools version '9.0.6' is older than that of the runtime '9.0.9'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
Done. To undo this action, use 'ef migrations remove'
but I don't see the tables anywhere in the DB.

Then Grok told me to do this:
dotnet ef database update

Which eventually terminated with the error:
PROCEDURE 'sp_getapplock' is not supported.

Is it possible to do EntityFramework Code First developement in a Fabric SQL Database? If not, when will that be supported?





1 ACCEPTED SOLUTION
drew-sk
Microsoft Employee
Microsoft Employee

Hi @Shawn_Eary -

 

EF Core migrations do work with SQL database in Fabric, there's a mistake in the previous reply.

 

It appears you may have grabbed the connection information for the read-only SQL analytics endpoint instead of the SQL database in Fabric - an understandable point of confusion that's come up a few times. 

 

Your connection string for SQL db in Fabric would look similar to:

 

Data Source=x6eps4xrq2xudenlfv6naeo3i4-fewuicewklvrnklvejkll.database.fabric.microsoft.com,1433;Initial Catalog=ContosoUniversity-a11e1987-145c-4fb5-8934-e6136cbf6128;Multiple Active Result Sets=False;Connect Timeout=30;Encrypt=True;Trust Server Certificate=False;Authentication=Active Directory Interactive
 
I highlighted 2 parts that help discern if you're connecting to the actual SQL database:
1. the server name ends with ".database.fabric.microsoft.com"
2. the database name has a guid appended on the end
 
If your connection string is to the read-only SQL analytics endpoint, the server name ends with ".datawarehouse.fabric.microsoft.com".
 
drewsk_0-1758303309110.png

 

 
Please let me know if this gets you rolling again, or if you're still unable to apply the EF migrations to SQL db in Fabric. We can potentially hop on a call to troubleshoot.
 
 

View solution in original post

6 REPLIES 6
drew-sk
Microsoft Employee
Microsoft Employee

Hi @Shawn_Eary -

 

EF Core migrations do work with SQL database in Fabric, there's a mistake in the previous reply.

 

It appears you may have grabbed the connection information for the read-only SQL analytics endpoint instead of the SQL database in Fabric - an understandable point of confusion that's come up a few times. 

 

Your connection string for SQL db in Fabric would look similar to:

 

Data Source=x6eps4xrq2xudenlfv6naeo3i4-fewuicewklvrnklvejkll.database.fabric.microsoft.com,1433;Initial Catalog=ContosoUniversity-a11e1987-145c-4fb5-8934-e6136cbf6128;Multiple Active Result Sets=False;Connect Timeout=30;Encrypt=True;Trust Server Certificate=False;Authentication=Active Directory Interactive
 
I highlighted 2 parts that help discern if you're connecting to the actual SQL database:
1. the server name ends with ".database.fabric.microsoft.com"
2. the database name has a guid appended on the end
 
If your connection string is to the read-only SQL analytics endpoint, the server name ends with ".datawarehouse.fabric.microsoft.com".
 
drewsk_0-1758303309110.png

 

 
Please let me know if this gets you rolling again, or if you're still unable to apply the EF migrations to SQL db in Fabric. We can potentially hop on a call to troubleshoot.
 
 

Entity Framework is now working in a Fabric SQL Database for me. I have not created a new table yet, but I migrated an Azure SQL Server database over to Fabric and I am able to read from and update it as expected using the .database.fabric.microsoft.com endpoint. 

We should consider this ticket closed unless I run into a problem later when creating a new table/POCO. Even if I have a problem, I have a way by which I can continue to use Entity Framework with Fabric SQL Database.

Thanks Microsoft!!!!

Is there some kind of firewall setting that needs to be toggled? The only way I can connect to a Fabric SQL database through the write/update endpoint "[myServerName].database.fabric.microsoft.com,1433" is to use the Open In -> SQL Server Management Studio menu option inside the Fabric Web Portal. 

Attempts to connect via Entity Framework.Core using C# fail as well. It feels like there is a setting my tenant admin needs to clear for me.

Hmm, that is odd. There's no firewall settings to configure on the Fabric side. What other connection options are failing for you?

I wonder if these apps are attempting to connect to "<default>" or "master", instead of the specific database.

 

We can try out a plain C# console app and see if that gives us any insights into the connectivity -

 

ConnectionTester.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
  </ItemGroup>

  <ItemGroup>
    <None Include="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

 

 appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=yourcxninfo.database.fabric.microsoft.com,1433;Initial Catalog=AdventureWorks-20ba15a4-b4f9-4d46-ad10-ddd9d0b7a6ea;Multiple Active Result Sets=False;Connect Timeout=30;Encrypt=True;Trust Server Certificate=False;Authentication=Active Directory Interactive"
  }
}

 

 

Program.cs

using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using System.Diagnostics;

namespace ConnectionTester;

class Program
{
    private static IConfiguration? _configuration;
    
    static async Task Main(string[] args)
    {
        // Build configuration from appsettings.json
        _configuration = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .Build();
        
        Console.WriteLine("SQL Database Connection Tester");
        Console.WriteLine("==============================");
        Console.WriteLine();
        
        var connectionString = _configuration?.GetConnectionString("DefaultConnection");
        if (string.IsNullOrEmpty(connectionString))
        {
            Console.WriteLine("✗ Error: No connection string found in appsettings.json");
            return;
        }
        
        await TestDatabaseConnectionAsync(connectionString);
        
        Console.WriteLine();
        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }
    
    private static async Task TestDatabaseConnectionAsync(string connectionString)
    {
        var stopwatch = Stopwatch.StartNew();
        
        try
        {
            Console.WriteLine("Attempting to connect to the database...");
            
            using var connection = new SqlConnection(connectionString);
            
            // Test opening the connection
            await connection.OpenAsync();
            Console.WriteLine("✓ Successfully connected to the database!");
            
            // Test executing a simple query
            Console.WriteLine("Testing query execution...");
            using var command = new SqlCommand("SELECT @@VERSION as ServerVersion, GETDATE() as CurrentTime", connection);
            using var reader = await command.ExecuteReaderAsync();
            
            if (await reader.ReadAsync())
            {
                Console.WriteLine("✓ Query execution successful!");
                Console.WriteLine($"  Current Server Time: {reader["CurrentTime"]}");
            }
            
            stopwatch.Stop();
            Console.WriteLine($"✓ Connection test completed successfully in {stopwatch.ElapsedMilliseconds}ms");
        }
        catch (SqlException sqlEx)
        {
            stopwatch.Stop();
            Console.WriteLine($"✗ SQL Server error occurred after {stopwatch.ElapsedMilliseconds}ms:");
            Console.WriteLine($"  Error Number: {sqlEx.Number}; Severity: {sqlEx.Class}; State: {sqlEx.State}; Message: {sqlEx.Message}");
        }
        catch (Exception ex)
        {
            stopwatch.Stop();
            Console.WriteLine($"✗ General error occurred after {stopwatch.ElapsedMilliseconds}ms:");
            Console.WriteLine($"  Type: {ex.GetType().Name}");
            Console.WriteLine($"  Message: {ex.Message}");
        }
    }
    
}

 

This C# program works as expected for me. I'm still looking into my other issues.

v-sathmakuri
Community Support
Community Support

Hi @Shawn_Eary ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

EF Core can be used to connect to Fabric SQL DB and carry out basic CRUD operations. However, EF Core Migrations that depend on unsupported system procedures are not available. As an alternative, you can manually create SQL scripts from your EF model and execute them in Fabric, though this disrupts the Code First automation process.

 

Thank you!!

Helpful resources

Announcements
September Fabric Update Carousel

Fabric Monthly Update - September 2025

Check out the September 2025 Fabric update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors