Invalid Column name ID-Entity Framework

c# entity-framework-6

Question

My database has a table with the following structure:

CREATE TABLE [dbo].[FDTransaction]
(
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [FamilyId] [int] NULL,
    [BankId] [int] NULL,
    [Account_No] [numeric](25, 0) NULL,
    [Amount] [int] NULL,
    [Interest_Percent] [decimal](18, 0) NULL,
    [Tenure] [int] NULL,
    [MaturityDate] [datetime] NULL,
    [InterestAmount] [int] NULL,

    CONSTRAINT [PK_FDTransaction] 
        PRIMARY KEY CLUSTERED ([ID] ASC)
) ON [PRIMARY]

I have a model class in my code that represents the database table:

 public class FDTransaction
 {
        [Key]
        public int ID { get; set; }     
        public int Familyid { get; set; }
        public int BankId { get; set; }
        public decimal Account_No { get; set; }
        public int Amount { get; set; }
        public double Interest_Percent { get; set; }
        public int Tenure { get; set; }
        public DateTime MaturityDate { get; set; }
        public int interestAmount { get; set; }
}

When I add a record to the table at the line below, I get an error.

dbentities.Transactions.Add(transaction);

The error stack is also below.

       StackTrace:
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
            at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
            at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
            at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
            at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
            at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
            at System.Data.Entity.Internal.InternalContext.SaveChanges()
       InnerException: System.Data.SqlClient.SqlException
            HResult=-2146232060
            Message=Invalid column name 'ID'.
Invalid column name 'ID'.
            Source=.Net SqlClient Data Provider
            ErrorCode=-2146232060
            Class=16
            LineNumber=5
            Number=207

As previously said, I do have a columnID at a table. I also own property.ID at schoolFDTransaction . I still can't add an entry to the database.

1
2
4/1/2018 12:49:50 PM

Popular Answer

ZZZ_tmp
0
4/1/2018 1:40:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow