Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Invalid Column Name
Message
De
25/06/2014 12:06:04
 
 
À
24/06/2014 20:01:19
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602256
Message ID:
01602435
Vues:
73
>>>>>>I think its actually supposed to be
>>>>>>
>>>>>>public Guid rnh_rtefk { get; set; }
>>>>>> [ForeignKey("rnh_rtefk")]
>>>>>>public virtual Route Route { get; set; }
>>>>>>
>>>>>>
>>>>>>The way you have it may not generate any errors, but you might want to verify that the route property is still loading correctly.
>>>>>
>>>>>Both ways run without error and both ways return null for Route even though there definitely is a a route with a matching key. :(
>>>>>
>>>>>Any idea why that would be?
>>>>
>>>>Offhand the only thing I can think of is that you have lazy loading disabled, or your object isn't currently being tracked by the context. Even if lazy loading is enabled, you may want to try explicitly loading the route (see http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/reading-related-data-with-the-entity-framework-in-an-asp-net-mvc-application). Also, enable the database log and check the output it produces when you try to load the route.
>>>
>>>I'm pretty sure I had this working before so I must have changed something when fiddling around with that previous error. I am not seeing anywhere that I am disabling lazy loading. What do you mean by "your object isn't currently being tracked by the context"?
>>>
>>>How do I enable the database log?
>>>
>>>Thanks for all your help on this!
>>
>>If your entity is passed in from an external source, created as a new object, or retrieved when change tracking is disabled, it will be in a detached state. Detached entities won't load their navigation properties via lazy loading. If you loaded it from the database using default settings, it should be tracked.
>>
>>Instructions on the database log can be found here: http://msdn.microsoft.com/en-us/data/dn469464.aspx
>
>Thanks. I did find some code in the Uow.cs:
>
>
// Load navigation properties explicitly (avoid serialization trouble)
>DbContext.Configuration.LazyLoadingEnabled = false;
>
>So I guess that explains it. What serialization trouble could John Papa have been trying to avoid? Is this generally a good thing to do?

If you are serializing the entity, you don't want to serialize the route and its properties as well. So for Web API where you are serializing the data, it is a good thing to do. If you want to load the route, you will need to explicitly do so via the include function, or loading it manually.


>
>However, when I commented out that line it didn't make a difference.
>
>I added in:
>
>
DbContext.Database.Log = Console.Write;
>
>and that appears to send output to the Output window, in VS, is that right?
>
>If so it looks like only the query to the top level table is running, no calls to the related tables show up there.

Yes, that will send the output to the Output window.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform