-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support separation of query and update mapping #15671
Comments
@bdebaere, no EF do not support such operations. Check this extension and you will be able to do that. |
Notes from triage: we should consider this as part of greater flexibility in update versus query mapping. This has overlap with:
|
@ajcvickers I have working code which listens to an extension method ToView(). If there is no view mapped to the entity, the table name is taken. I can create a PR soon that you can take a look at. |
See #15699 (comment) for an additional workaround and some more comments on this feature. Also, see #245 for the overall stored-proc mapping feature |
@ajcvickers Thank you very much for your response. Unfortunately I cannot use FromSql as, unless I'm mistaken, this doesn't function well together with IQueryable. |
@bdebaere Can you give some more details on what you mean by that? |
@ajcvickers As far as I'm aware there is no way to include navigation properties, filter on them, select on them, et cetera. |
@bdebaere The var entities
= context.View<Blog>("BlogsView")
.Include(e => e.Posts)
.Where(e => e.Title == "OneUnicorn")
.ToList(); translates to SELECT [e].[Id], [e].[Title]
FROM (
SELECT * FROM [BlogsView]
) AS [e]
WHERE [e].[Title] = N'OneUnicorn'
ORDER BY [e].[Id]
SELECT [e.Posts].[Id], [e.Posts].[BlogId], [e.Posts].[Title]
FROM [Post] AS [e.Posts]
INNER JOIN (
SELECT [e0].[Id]
FROM (
SELECT * FROM [BlogsView]
) AS [e0]
WHERE [e0].[Title] = N'One Unicorn'
) AS [t] ON [e.Posts].[BlogId] = [t].[Id]
ORDER BY [t].[Id] |
@ajcvickers That's nice but I need something which will do that automatically for the entities and their includes because, using OData, by default I have no control over the creation and execution of the expression tree. |
@bdebaere I'm out of ideas. |
Note to implementor:
|
@AndriySvyryd I'm looking at this in terms of new feature. Does this work in the update pipeline yet? This: modelBuilder.Entity<Blog>(b =>
{
b.ToTable("Blogs");
b.ToView("BlogsView");
}); Causes SaveChanges to throw. Assuming it doesn't yet work end-to-end, we should probably not announce this in preview 2, right? /cc @JeremyLikness |
@ajcvickers - What is the exception? |
@ajcvickers Correct I'm just starting the work on the update pipeline. All of this will only start being usable when TPT is done. |
Throw if no model or types are provided Part of #15671
Throw if no model or types are provided Part of #15671
Throw if no model or types are provided Part of #15671
Copied from my StackOverflow post.
I've since gone through the code and noticed that SqlServerQuerySqlGenerator is not used to generate non-SELECT queries, am I correct? So I'm left with adjusting the code to a custom EF Core version and add a ViewAttribute which it uses during
INSERT INTO SELECT ... FROM
generation or multiple classes which is the least preferred option by the person pulling my strings. Is there nothing better?The text was updated successfully, but these errors were encountered: