Enable flexible FromSql mapping
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by reviewing the linked issues 17063 and 13358, then inspect the existing ToSqlQuery, FromSql, and FromSqlRaw entry points. Define the supported mapping and parameter configuration behavior, including named, default, and JSON-column queries, before identifying the required tests and implementation scope.
Written by the indexing model from the issue text.
Description
This builds upon https://github.com/dotnet/efcore/issues/17063, https://github.com/dotnet/efcore/issues/13358 to enable different mappings for different SQL queries and to allow parameter configuration. This would also support JSON columns.
It would be configured like so:
modelBuilder
.Entity<Blog>()
.ToSqlQuery("GetDeletedBlogs", "select id as BlogId, name as BlogName from Blogs where Deleted={0}",
q =>
{
q.Propety(b => b.Id).ToColumn("BlogId"));
q.Propety(b => b.Name).ToColumn("BlogName"));
q.Parameter("0").HasType("bit"));
});
This also allows setting the default (unnamed) SQL query:
modelBuilder
.Entity<Blog>()
.ToSqlQuery("select id as BlogId, name as BlogName from Blogs where Deleted={0}",
q => {});
A default mapping that would be used for FromSql queries and as a base configuration for mapped queries is configured like so:
modelBuilder
.Entity<Blog>()
.ToSqlQuery(q =>
{
q.Propety(b => b.Id).ToColumn("BlogId"));
q.Propety(b => b.Name).ToColumn("BlogName"));
});
And used like so:
var deletedBlogs = context.Set<Blog>().FromNamedSql("GetDeletedBlogs", true).ToList();
or
var deletedBlogs = context.Set<Blog>().FromNamedSqlRaw("GetDeletedBlogs",
"select id as BlogId, name as BlogName from Blogs where Deleted={0}",
true)
.ToList();
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100