When you are getting following error, check your model
class mapping properties filed matching with your SQL server table column or
not.
If any of the properties don't match with SQL Server table columns you
will get the following error.
In my
case, I am using the Address properties field in Employee model class mapping, i.e. not
exist in the SQL Server Employee table.
Employee Model Class Mapping
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace MvcDemo.Models
{
[Table("tblEmployee")]
public class Employee
{
[Key]
public int EmployeeId
{ get; set; }
public string Name
{ get; set; }
public string Gender
{ get; set; }
public string City
{ get; set; }
public string Address
{ get; set; }
}
}
Employee Table Structure in SQL Server
Create table tblEmployee
(
EmployeeId int Primary Key Identity(1,1),
Name nvarchar(50),
Gender nvarchar(10),
City nvarchar(50),
DateOfBirth DateTime,
DepartmentId int
)
No comments:
Post a Comment