坏的存储属性:未知原因 [英] Bad Storage property: unknown cause

查看:72
本文介绍了坏的存储属性:未知原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么原因导致成员'resetQueryStatus.Employee.employeeId'上此 Bad Storage属性:'_employeeId'.异常?

What is causing this Bad Storage property: '_employeeId' on member 'resetQueryStatus.Employee.employeeId'. exception?

异常似乎在我的连接点上

The exception seems to be at my connection point here:

 [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;
        }

    }
}

这是我的查询代码,用于从上述实体获取值:

Here's my query code to get values from the above entities:

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

请帮助谢谢!

推荐答案

发现我的错误:

存储字段/属性不能公开.

Storage field/ property cannot be public.

当它是私人的那一刻,问题就消失了.希望这对下一次遇到同样问题的人有所帮助. :)

The moment it was private, the issue was gone. Hopes this helps others with the same issue next time. :)

这篇关于坏的存储属性:未知原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆