Skip to content
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

LoadRelatedEntities() - missing table in generated SQL #80

Closed
luboshl opened this issue Sep 12, 2015 · 4 comments
Closed

LoadRelatedEntities() - missing table in generated SQL #80

luboshl opened this issue Sep 12, 2015 · 4 comments
Labels
Milestone

Comments

@luboshl
Copy link
Contributor

luboshl commented Sep 12, 2015

Hi Tony,

first thank you for your Trackable Entities :)

I have problem with DbContextExtensions.LoadRelatedEntities() method when I use entity which references other entity with base class. (I uploaded full example to https://dl.dropboxusercontent.com/u/91293338/TrackableEntities/Demo.zip)

[Table("LightOnActions")]
public class LightOnAction : ActionBase
{
public int? Light_Id { get; set; }

[Required]
[ForeignKey("Light_Id")]
public LightDevice Light { get; set; }
}

[Table("LightDevices")]
public class LightDevice : DeviceBase { ... }

[Table("Actions")]
public abstract class ActionBase : EntityBase { ... }

When I use LoadRelatedEntities, I get System.Data.Entity.Core.EntitySqlException, because the generated SQL is "SELECT VALUE x FROM AS x WHERE x.Id IN {1}" - table is missing.

Example:

using (var context = new DemoContext())
{
var action = new LightOnAction
{
...
Light = new LightDevice
{
...
TrackingState = TrackingState.Added
},
TrackingState = TrackingState.Added
};

context.ApplyChanges(action);
context.SaveChanges();

// here I get the Exception
context.LoadRelatedEntities(action);
action.AcceptChanges();
}

Is there a way to solve the problem in this case?

@tonysneed
Copy link
Collaborator

Hello @luboshl,

I'm sorry it's taken me to long to respond. Been crazy busy until now. I've taken a look at your demo and stepped through the code. It seems that LoadRelatedEntities probably has a problem with FK values which are nullable. I'll see if I can replicate this in a small failing test.

In the meantime, were you able to find a workaround?

Cheers,
Tony

@tonysneed tonysneed added the bug label Dec 10, 2015
@tonysneed
Copy link
Collaborator

I'm still trying to reproduce the error. I have tried nullable foreign keys, and also reference types which inherit from a base class, but so far no errors. Next, I'll try multi-level reference types, in order to approximate the demo which @luboshl updloaded.

@tonysneed tonysneed added this to the v 2.5.3 milestone Dec 15, 2015
@tonysneed
Copy link
Collaborator

I was finally able to locate the source of the problem, then I produced a failing test to replicate it, and I fixed the problem with PR #93: Load Related Entities for Derived Reference Types.

@luboshl
Copy link
Contributor Author

luboshl commented Dec 24, 2015

Thank you, Tony!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants