September 22nd, 2025
intriguingheart2 reactions

Using the new SqlVector type with EF Core and Dapper

Davide Mauri
Principal Product Manager

Azure SQL vector support has been generally available for a few months now, and the ecosystem is quickly evolving to make working with vectors in your applications as seamless and efficient as possible.

With the release of Microsoft.Data.SqlClient 6.1, developers can now take advantage of binary transport for vector data via the new SqlVector class. This significantly improves performance when moving vectors between your application and the database, laying the groundwork for optimized vector handling in popular .NET libraries like:

  • EF Core 9
  • EF Core 10
  • Dapper

Here’s how you can start using SqlVector in each of these libraries:

EF Core 9

To enable binary vector transfer in EF Core 9, make sure to use the appropriate extension EFCore.SqlServer.VectorSearch. Just add the package and configure your model to use SqlVector:

builder.Services.AddDbContext<MyContext>(options =>
  options.UseSqlServer("<connection string>", o => o.UseVectorSearch()));

then tell EF Core what property of your POCO object should use the vector type:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<MyPOCO>().Property(p => p.Embedding).HasColumnType("vector(1536)");
}

and you’re good to go! Of course if you prefer using Data Annotations instead of Fluent API, that is supported too. The extension also add support for EF.Functions.VectorDistance for using VECTOR_DISTANCE in T-SQL to find closest vectors to a given query vector.

EF Core 10

EF Core 10 introduces native support for SqlVector, making it even easier to work with vector data. You can store and manipulate vectors and use the VECTOR_DISTANCE function via the new EF.Functions.VectorDistance() method in your LINQ queries. Just tell EF Core what property is mapped to a vector, and it is done:

public class Blog
{
    // ...

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

If you prefer using Fluent API instead of Data Annotation that’s an option too, of course. Make sure to check out everything that is possible with EF Core and vectors in the official documentation page: Vector search in the SQL Server EF Core Provider

Dapper

No need to wait for a Dapper update! Since Dapper builds on top of SqlClient, you can register a custom Type Handler to map float[] or ReadOnlyMemory<float> to use SqlVector seamlessly:

public class VectorTypeHandler: SqlMapper.TypeHandler<float[]>
{
    public override float[] Parse(object value)
    {
        return ((SqlVector<float>)value).Memory.ToArray();
    }

    public override void SetValue(System.Data.IDbDataParameter parameter, float[]? value)
    {
        parameter.Value = value is not null ? new SqlVector<float>(value) : DBNull.Value;
        ((SqlParameter)parameter).SqlDbType = SqlDbTypeExtensions.Vector;
    }
}

Conclusions

That’s it! With just a few lines of code, you can unlock high-performance vector operations in your .NET applications. Fast, easy, and future-ready. The end-to-end samples for all the mentioned libraries are available in the following GitHub repo:

https://github.com/Azure-Samples/azure-sql-db-vector-search/tree/main/DotNet

Author

Davide Mauri
Principal Product Manager

Principal Product Manager in Azure SQL, with a career in IT spanning since 1997, earning the prestigious Data Platform MVP status for 12 consecutive years. Currently, he serves as the Principal Product Manager for Azure SQL Database, focusing on developers and AI.

0 comments