Skip to content

Add support for EF Core 10 #869

@sjh37

Description

@sjh37

https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-10.0/whatsnew

Vector support (Azure or SQL Server 2025)

[Column(TypeName = "vector(1536)")]
public SqlVector<float> Embedding { get; set; }

JSON type support (Azure or SQL Server 2025)

public class Blog
{
    public int Id { get; set; }
    public required BlogDetails Details { get; set; }
}

public class BlogDetails { ... }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>().ComplexProperty(b => b.Details, b => b.ToJson());
}
CREATE TABLE [Blogs] (
    ...
    [Details] json NOT NULL,
);

JSON

Instead of

CREATE TABLE [Customers] (
    [Id] int NOT NULL IDENTITY,
    [Name] nvarchar(max) NOT NULL,
    [BillingAddress_City] nvarchar(max) NOT NULL,
    [BillingAddress_PostalCode] nvarchar(max) NOT NULL,
    [BillingAddress_Street] nvarchar(max) NOT NULL,
    [BillingAddress_StreetNumber] int NOT NULL,
    [ShippingAddress_City] nvarchar(max) NOT NULL,
    [ShippingAddress_PostalCode] nvarchar(max) NOT NULL,
    [ShippingAddress_Street] nvarchar(max) NOT NULL,
    [ShippingAddress_StreetNumber] int NOT NULL,
    CONSTRAINT [PK_Customers] PRIMARY KEY ([Id])
);

You can now have

public class Customer
{
    ...
    public Address ShippingAddress { get; set; }
    public Address? BillingAddress { get; set; }
}
...
modelBuilder.Entity<Customer>(b =>
{
    b.ComplexProperty(c => c.ShippingAddress, c => c.ToJson());
    b.ComplexProperty(c => c.BillingAddress, c => c.ToJson());
});
CREATE TABLE [Customers] (
    [Id] int NOT NULL IDENTITY,
    [Name] nvarchar(max) NOT NULL,
    [ShippingAddress] json NOT NULL,
    [BillingAddress] json NOT NULL,
    CONSTRAINT [PK_Customers] PRIMARY KEY ([Id])
);

This can make it tricky as you have no idea what model is stored in the json unless you read a row.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions