2015-04-08 32 views
2

導致此問題的原因存儲屬性錯誤:成員'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 
} 

employeeDetails實體類

//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 

請幫助的感謝!

回答

2

發現我的錯誤:

存儲字段/屬性不能公開。

當它是私人的時候,問題就消失了。希望下次能夠幫助其他人解決同樣的問題。 :)