-
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
Issue with Computed Fields using User Defined Functions #6044
Comments
Note for triage: this seems to be an issue with the update pipeline. @AndriySvyryd I'm going to send out a PR containing a failing test. |
@skimedic The second issue you list is actually by design. EF does identity resolution when running queries such that if an entity with the same ID is already being tracked by the context, then it is not re-created or updated by the query. There is an item on our backlog (#1203) to implement a Reload method that would allow the values in the entity to be refreshed based on the current values in the database. |
@ajcvickers ok, thanks for the info. I have a simple workaround for the second issue, so I'm not that concerned about it. Just wanted bring it up for completeness. I will eagerly wait for the reload to bubble to the top of the backlog :-) |
@AndriySvyryd when we understand this more we can make the 1.1 vs 1.0.1 call |
@AndriySvyryd One thing that came up in triage is whether or not this works if batching is switched off? |
@skimedic You would need to add This would still be the case without batching and in EF6 as far as I can tell. |
@AndriySvyryd this means no action on the EF side right? |
@rowanmiller Yes, unless we want to mention this in the docs |
ok, I will try that and report back - sorry, just saw this. |
@AndriySvyryd I don't see how this fixes anything. I updated my UDF to this:
Result StackTrace:
Here is the SQL captured through SQL Server Profiler: exec sp_executesql N'SET NOCOUNT ON;
DECLARE @inserted0 TABLE ([OrderTotalComputed] money, [TimeStamp] varbinary(8));
UPDATE [Store].[Orders] SET [ShipDate] = @p0
OUTPUT INSERTED.[OrderTotalComputed], INSERTED.[TimeStamp]
INTO @inserted0
WHERE [Id] = @p1 AND [TimeStamp] = @p2;
SELECT [OrderTotalComputed], [TimeStamp] FROM @inserted0;
',N'@p1 int,@p0 datetime,@p2 varbinary(8)',@p1=2,@p0='2016-07-24 16:44:14.777',@p2=0x00000000000117AB Please let me know what I am missing is with schemabinding fixes this problem. |
I don't believe this should have been closed. @rowanmiller did you get this working somewhere? |
Reopening to discuss in triage based on comments from @skimedic |
SpyStore.DAL.zip |
please let me know if I can help in any additional way to diagnose this. ty. |
My bad, As a workaround you can configure the property as
|
This is the same issue that was described in #5793, but was never resolved because of a lack of code samples. I've attached code that illustrates the issues. If it's too much code, I can make a smaller sample, but it should be pretty clear. There are actually two issues that I am running into, don't know if they are related or if the other one should be a new issue.
Property definition:
In my context:
OnModelCreating:
When I first create an order record, it works fine. If I update an existing record I get the following error:
Result StackTrace:
Result Message:
An error occurred while updating the entries. See the inner exception for details.
Column 'inserted.OrderTotalComputed' cannot be referenced in the OUTPUT clause because the column definition contains a subquery or references a function that performs user or system data access. A function is assumed by default to perform data access if it is not schemabound. Consider removing the subquery or function from the column definition or removing the column from the OUTPUT clause.
In the attached code, execute the SpyStore.DAL.Tests.Context.OrderTests.ShouldUpdateAnOrder test to see the error in action.
The failing test (where the value doesn't get updated in the same DbContext) is here: SpyStore.DAL.Tests.Context.OrderTests.ShouldGetOrderTotalAfterAddingAnOrderDetail
EF Core version: RTM (1.0.0.0)
Operating system: Win10
Visual Studio version: 2015
SpyStore.DAL.zip
The text was updated successfully, but these errors were encountered: