I have created a simple class and a list based on this class. When i try to populte this list and send to view iam getting an error. Please view my class and custom mapper model based on database.
Folloiwng is the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcModal.Models
{
public class mytransaction
{
public int Id { get; set; }
public int my_trn_id { get; set; }
public string Description { get; set; }
public List<mytransaction> Translist { get; set; }
}
}
Following is the custom database mapper class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using MvcModal.Models;
namespace MvcModal.Models
{
public class PrContext : DbContext
{
static string _conString = @"Data Source=.\sqlexpress;Initial Catalog=MyDb;Integrated Security=True";
public PrContext() : base(_conString) { }
public DbSet<mytransaction> MyTransactions { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<PrContext>(null);
modelBuilder.Configurations.Add(new NewTransactMapper());
}
public class NewTransactMapper : EntityTypeConfiguration<mytransaction>
{
public NewTransactMapper()
{
this.ToTable("mytransaction");
this.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.HasKey(m => m.my_trn_id);
}
}
}
}
Following is the error image.
Please view the red circuled error and see the mytransactions_my_trn_id text. mytransaction is my table name and my_trn_id is my column name. Rest of the columns have no issue, but this making me insane.
Please anyone guide what iam missing and how can i make my table name and column isolate and resolve this error. Thanks in advance.