Personel이라는 이름의 db 테이블에 필드 이름이 있습니다. ID, 성, 이름, 급여 및 위치. DataContext
을 확장 한 클래스를 만든 다음 속성이있는 열을 만듭니다. 나는이 수업에서 itarate를 시도했다. 그러나 나는이 예외를 아래에서 얻고있다. 필드 이름과 값이 정확합니다.이 오류의 원인을 잘 모릅니다.이 클래스를 열거 할 수 없습니다.
지정된 캐스트가 유효하지 않습니다.
이
은public class PersonelDbContext:DataContext
{
public Table<Personel> Personel;
public PersonelDbContext()
: base("server=.\\sqlexpress;database=Project;User Id=sa;Password=1")
{
}
}
[Table(Name="Personel")]
public class Personel {
private int _id;
private string _name;
private string _lastname;
private int _salary;
private string _position;
[Column(Name="Id",Storage="_id",DbType="Int not null",IsPrimaryKey=true,IsDbGenerated=true)]
public int ID
{
get { return _id; }
set { _id = value; }
}
[Column (Name="Name",Storage="_name",DbType="Int not null identity")]
public string Name
{
get { return _name; }
set { _name = value; }
}
[Column(Name="LastName",Storage="_lastname",DbType="Nvarchar not null")]
public string Lastname
{
get { return _lastname; }
set { _lastname = value; }
}
[Column(Name="Salary",Storage="_salary",DbType="Int not null")]
public int Salary
{
get { return _salary; }
set { _salary = value; }
}
[Column(Name="Position",Storage="_position",DbType="Nvarchar not null")]
public string Position
{
get { return _position; }
set { _position = value; }
}
}
//}
static void Main(string[] args)
{
PersonelDbContext dbcontext = new PersonelDbContext();
var query = from c in dbcontext.Personel select c;
foreach (var item in query)
{
Console.WriteLine("Id:", item.Name);
Console.WriteLine("Id:", item.Lastname);
}
Console.ReadKey();
}
}
있는 당신이 중 하나를 의미 할 수 있습니다? –