-
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
Foreign key with backing field producing invalid sql #7147
Comments
@dmcweeney Can you post the code for the Region class? |
@ajcvickers I discovered a workaround by adding an empty setter from the Service.RegionName property. With this EFC generates the correct sql.
For the record the following is the code for the Region class
|
Note for triage: This looks like an issue in model building. The model has a shadow FK created, presumably because the RegionName property is not mapped at the time the HasOne call is made. This gets replaced by the correct FK once the ForeignKey call is made later in the chain, but the FK and shadow property are left dangling rather than being removed.
|
This is probably already fixed in 2.0.0 |
Confirmed fixed |
Hi,
I'm getting the following error when trying to define a backing field for a foreign key field.
{System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'RegionName1'.
Entity def is simple - RegionName is FK to table Regions and Region in included as a navigation property.
Note the following works when not using backing fields.
The modelbuilder customization is as follows:
And query includes the Region reference to get it loaded.
Results in the following sql being generated:
Note incorrect inclusion of column [RegionName1].
SELECT TOP(2) [service].[ServiceId], [service].[RegionName], [service].[RegionName1]
FROM [Services] AS [service]
INNER JOIN [Regions] AS [r] ON [service].[RegionName] = [r].[Name]
WHERE [service].[ServiceId] = @__serviceId_0
Is this a bug or am I doing something stupid.
Using EF 1.1
Thanks
Donal
The text was updated successfully, but these errors were encountered: