导致 Bad Storage属性的原因是什么:成员'resetQueryStatus.Employee.employeeId'上的'_employeeId'。异常?
这个例外似乎在我的连接点:
[Database]
public class FireEvacuation : DataContext
{
public Table<Employee> EmployeeDetails;
public Table<EmpDepartment> Department;
public Table<EmpStatus> Status;
**public FireEvacuation(string connection) : base(connection) { }** //exception thrown here
}
//create class and map it to FireEvacuation table
[Table(Name = "EmployeeDetails")]
public class Employee
{
public string _employeeId;
//designate employeeId property on the entity class as representing column in the database table
//employeeId is designated to be a primary key column in the database
//employeeName is designated as private storage ==> allows LINQ to SQL to directly store and retrieve values
[Column(IsPrimaryKey = true, Storage = "_employeeId", DbType = "int(System.Int32) NOT NULL")]
public string employeeId
{
get
{
return this._employeeId;
}
set
{
this._employeeId = value;
}
}
public string _employeeName;
//designate employeeName property on the entity class as representing column in the database table
//employeeName is designated as private storage ==> allows LINQ to SQL to directly store and retrieve values
[Column(Storage = "_employeeName", DbType = "nvarchar(50) NULL")]
public string employeeName
{
get
{
return this._employeeName;
}
set
{
this._employeeName = value;
}
}
public string _departmentId;
[Column(Storage = "_departmentId", DbType = "int(System.Int32) NULL")]
public string departmentId
{
get
{
return this._departmentId;
}
set
{
this._departmentId = value;
}
}
public string _statusId;
[Column(IsPrimaryKey = true, Storage = "_statusId", DbType = "int(System.Int32) NULL")]
public string statusId
{
get
{
return this._statusId;
}
set
{
this._statusId = value;
}
}
}
[Table(Name = "Department")]
public class EmpDepartment
{
public string _departmentId;
[Column(IsPrimaryKey = true, Storage = "_departmentId", DbType = "int(System.Int32) NOT NULL")]
public string departmentId
{
get
{
return this._departmentId;
}
set
{
this._departmentId = value;
}
}
public string _departmentName;
[Column(Storage = "_departmentName", DbType = "nvarchar(50) NOT NULL")]
public string departmentName
{
get
{
return this._departmentName;
}
set
{
this._departmentName = value;
}
}
}
[Table(Name = "Status")]
public class EmpStatus
{
public string _statusId;
[Column(IsPrimaryKey = true, Storage = "_statusId", DbType = "int(System.Int32) NOT NULL")]
public string statusId
{
get
{
return this._statusId;
}
set
{
this._statusId = value;
}
}
public string _statusDescription;
[Column(Storage = "_statusDescription", DbType = "nvarchar(50) NOT NULL")]
public string statusName
{
get
{
return this._statusDescription;
}
set
{
this._statusDescription = value;
}
}
}
这是我从上述实体获取值的查询代码:
static void Main(string[] args)
{
// Use a connection string.
FireEvacuation db = new FireEvacuation
(@"C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\runSqlLinq\FireEvacuation.mdf");
do
{
// Attach the log to show generated SQL.
db.Log = Console.Out;
string name = "John";
//Query for account status
var query = from emp in db.EmployeeDetails
join stat in db.Status on emp._statusId equals stat._statusId
join dep in db.Department on emp._departmentId equals dep._departmentId
where emp._employeeName == name
select new { emp, stat, dep };
foreach (var q in query)
{
Console.WriteLine("Department Name = {0} Employee Name = {1} Status Name = {2}", q.dep._departmentName, q.emp._employeeName, q.stat._statusDescription);
}
}
while (Console.ReadKey(true).Key != ConsoleKey.Escape);
//Thread.Sleep(60000);
}//end of main
请帮助谢谢!
答案 0 :(得分:2)
发现我的错误:
存储字段/属性不能公开。
在私有的那一刻,问题就消失了。希望下次能帮助其他人解决同样的问题。 :)