System.Data.SqlClient.SqlException: Invalid column name 'Machine_Id'

I have the code of the first db using EF 6.
I faced a similar problem. I tried all the answers but none of them worked.

My objects:

public class UtilizationSummary
{
    public DateTime SummaryDate { get; set; }
    public Int32 ProcessKey { get; set; }
    public virtual ProcessInfo ProcessInfo { get; set; }
    public Guid MachineId { get; set; }
    public virtual Machine Machine { get; set; }
}

public class ProcessInfo
{
     public virtual Machine Machine { get; set; }
     public virtual Session Session { get; set; }
}

public class Machine
{
     public Guid Id { get; set; }
     public String Sid { get; set; }
}

      

The mappings are as follows:

public class UtilizationSummaryMap: EntityTypeConfiguration<UtilizationSummary>
{
     this.HasKey(pus=> new { pus.MachineId, pus.SummaryDate, pus.ProcessKey });
     this.Property(pus=> pus.MachineId).IsRequired();
     this.HasRequired(pus=> pus.Machine).WithMany().HasForeignKey(ma => ma.MachineId);
}

      

Access to use:

[HttpGet]
[ODataRoute("UtilizationSummary")]
[EnableQuery]
public IQueryable<UtilizationSummary> FilterUtilizationSummary() 
{
    var expression = ...some expression..;
    var result = db.UtilizationSummary.Where(expression);
    return result;
}

      

The following exception is thrown at 'return result':

"message":"Invalid column name 'Machine_Id'.","type":"System.Data.SqlClient.SqlException"

      

Printing result

gives:

SELECT 
    [Extent1].[ProcessKey] AS [ProcessKey], 
    [Extent1].[MachineId] AS [MachineId], 
    [Extent1].[SummaryDate] AS [SummaryDate],  
    [Extent1].[Machine_Id] AS [Machine_Id]
FROM [ProcessUtilizationMinuteSummary] AS [Extent1]

      

I don't understand why it is trying to access Machine_Id

, although I have given a mapping for the foriegn key.

Thank you in advance:)

+3
c # entity-framework-6 sqlexception asp.net-web-api2 odata-v4


source to share


No one has answered this question yet

See similar questions:

71
Entity Framework - invalid column name '* _ID "

or similar:

8
System.Data.SqlClient.SqlException: Invalid column name 'phone_types_phone_type_id'
3
System.Data.SqlClient.SqlException: Invalid column name 'GenreId'
2
System.Data.SqlClient.SqlException: 'Invalid column name' ApplicationRoleId '.'
1
System.Data.SqlClient.SqlException: Invalid object name 'dbo .__ TransactionHistory'
1
System.Data.SqlClient.SqlException: Invalid column name 'Gender_id'
1
System.Data.SqlClient.SqlException: 'Invalid column name'
0
System.Data.SqlClient.SqlException: 'Invalid column name' music '.'
0
System.Data.SqlClient.SqlException: Invalid column name 'conferID'
0
Zero foreign key code in Entity Framework first
0
System.Data.SqlClient.SqlException: Invalid column name 'Reference_Id'



All Articles
Loading...
X
Show
Funny
Dev
Pics