Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Invalid Column Name
Message
From
23/06/2014 21:13:07
 
 
To
All
General information
Forum:
ASP.NET
Category:
Entity Framework
Title:
Invalid Column Name
Environment versions
Environment:
C# 4.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01602256
Message ID:
01602256
Views:
107
Hi,

continuing work on my Web API project I have got 6 or 7 controllers to work but am getting an error on one of them that I cannot figure out:
innerException: {
message: "An error has occurred.",
exceptionMessage: "Invalid column name 'Route_rte_pk'. Invalid column name 'Route_rte_pk'.",
exceptionType: "System.Data.SqlClient.SqlException",
stackTrace: " at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)"
}
The error refers to "Route_rte_pk", but the controller that is causing the problem is RunSheetHeaders which should not have any column referring to "Route" or "rte_pk".

I have searched through the entire solution and not found this string anywhere. Any ideas where I should look?

< update >

I have looked into SQL Server Profiler and found that the sql being generated by Entity Framework is this:

SELECT
1 AS [C1],
[Extent1].[rnh_pk] AS [rnh_pk],
[Extent1].[rnh_date] AS [rnh_date],
[Extent1].[rnh_rtefk] AS [rnh_rtefk],
[Extent1].[Route_rte_pk] AS [Route_rte_pk]
FROM [dbo].[RunSheetHeader] AS [Extent1]

Route is a separate table which is joined to this table by the rnh_rtefk = Route.rte_pk

So I guess something is wrong in my model?

Here's my model definition code:
    [Table("RunSheetHeader")]
    public partial class RunSheetHeader
    {
        public RunSheetHeader()
        {
            RunSheetDetails = new HashSet<RunSheetDetail>();
        }

        [Key]
        public Guid rnh_pk { get; set; }

        [Column(TypeName = "date")]
        public DateTime rnh_date { get; set; }

        public Guid rnh_rtefk { get; set; }

        public virtual Route Route { get; set; }

        public virtual ICollection<RunSheetDetail> RunSheetDetails { get; set; }
    }
Can anyone see what I have done wrong? Do I need to post more code?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform