简体   繁体   English

C# LINQ to SQL 无效的对象名称

[英]C# LINQ to SQL Invalid Object Name

public class AMCOMDB : DataContext
{
        public Table<student> allStudents;
        public Table<aClass> allClasses;
        public AMCOMDB(string connection) : base(connection) { } 
}

[Table(Name = "student")]
public class student
{
        private string _studentName;

        [Column(IsPrimaryKey =true,Storage ="_studentName")]
        public string studentName
        {
            get { return this._studentName; }
            set { this._studentName = value; }
        }

        private string _LARType;

        [Column(Storage ="_LARType")]
        public string LARType
        {
            get { return this._LARType; }
            set { this._LARType = value; }
        }

        private string _studentType;

        [Column(Storage = "_studentType")]
        public string studentType
        {
            get { return this._studentType; }
            set { this._studentType = value; }
        }

        private string _aviationLevel;

        [Column(Storage = "_aviationLevel")]
        public string aviationLevel
        {
            get { return this._aviationLevel; } 
            set { this._aviationLevel = value; }
        }
        private string _airDefenseLevel;
        [Column(Storage = "_airDefenseLevel")]
        public string airDefenseLevel
        {
            get
            {
                return this._airDefenseLevel;
            }
            set
            {
                this._airDefenseLevel = value;
            }
        }
        private string _emergencyContact;
        [Column(Storage = "_emergencyContact")]
        public string emergencyContact
        {
            get
            {
                return this._emergencyContact;
            }
            set
            {
                this._emergencyContact = value;
            }
        }
[Table(Name = "grades")]
    public class grades
    {
        private string _studentName;
        [Column(IsPrimaryKey = true, Storage = "_studentName")]
        public string studentName
        {
            get
            {
                return this._studentName;
            }
            set
            {
                this._studentName = value;
            }
        }
        private int _ET;
        [Column(Storage = "_ET")]
        public int ET
        {
            get
            {
                return this._ET;
            }
            set
            {
                this._ET = value;
            }
        }
        private int _CP;
        [Column(Storage = "_CP")]
        public int CP
        {
            get
            {
                return this._CP;
            }
            set
            {
                this._CP = value;
            }
        }
        private int _SB;
        [Column(Storage = "_SB")]
        public int SB
        {
            get
            {
                return this._SB;
            }
            set
            {
                this._SB = value;
            }
        }
        private int _EC;
        [Column(Storage = "_EC")]
        public int EC
        {
            get
            {
                return this._EC;
            }
            set
            {
                this._EC = value;
            }
        }
        private int _finalGrade;
        [Column(Storage = "_finalGrade")]
        public int finalGrade
        {
            get
            {
                return this._finalGrade;
            }
            set
            {
                this._finalGrade = value;
            }
        }
       }
[Table(Name = "classes")]
    public class aClass
    {
        private string _classNumber;
        [Column(IsPrimaryKey = true, Storage = "_classNumber")]
        public string classNumber
        {
            get
            {
                return this._classNumber;
            }
            set
            {
                this._classNumber = value;
            }
        }
        private string _courseSeries;
        [Column(Storage = "_courseSeries")]
        public string courseSeries
        {
            get
            {
                return this._courseSeries;
            }
            set
            {
                this._courseSeries = value;
            }
        }
        private string _courseNumber;
        [Column(Storage = "_courseNumber")]
        public string courseNumber
        {
            get
            {
                return this._courseNumber;
            }
            set
            {
                this._courseNumber = value;
            }
        }
        private string _distanceLearning;
        [Column(Storage = "_distanceLearning")]
        public string distanceLearning
        {
            get
            {
                return this._distanceLearning;
            }
            set
            {
                this._distanceLearning = value;
            }
        }
        private string _classStartDate;
        [Column(Storage = "_classStartDate")]
        public string classStartDate
        {
            get
            {
                return this._classStartDate;
            }
            set
            {
                this._classStartDate = value;
            }
        }
        private string _classEndDate;
        [Column(Storage = "_classEndDate")]
        public string classEndDate
        {
            get
            {
                return this._classEndDate;
            }
            set
            {
                this._classEndDate = value;
            }
        }
        private string _primaryInstructor;
        [Column(Storage = "_primaryInstructor")]
        public string primaryInstructor
        {
            get
            {
                return this._primaryInstructor;
            }
            set
            {
                this._primaryInstructor = value;
            }
        }
        private string _secondaryInstructor;
        [Column(Storage = "_secondaryInstructor")]
        public string secondaryInstructor
        {
            get
            {
                return this._secondaryInstructor;
            }
            set
            {
                this._secondaryInstructor = value;
            }
        }
        private string _location;
        [Column(Storage = "_location")]
        public string location
        {
            get
            {
                return this._location;
            }
            set
            {
                this._location = value;
            }
        }
        private string _TDYCosts;
        [Column(Storage = "_TDYCosts")]
        public string TDYCosts
        {
            get
            {
                return this._TDYCosts;
            }
            set
            {
                this._TDYCosts = value;
            }
        }
        private string _studentCount;
        [Column(Storage = "_studentCount")]
        public string studentCount
        {
            get
            {
                return this._studentCount;
            }
            set
            {
                this._studentCount = value;
            }
        }
        private List<grades> _classGrades;
        [Column(Storage = "_classGrades")]
        public List<grades> classGrades
        {
            get
            {
                return this._classGrades;
            }
            set
            {
                this._classGrades = value;
            }
        }
AMCOMDB ADB = new AMCOMDB(connectionString);
        if (ADB.DatabaseExists())
        {

            var stud = ADB.GetTable<student>();
            var clas = ADB.GetTable<aClass>();
            IQueryable<string> query = from c in stud
                                       where c.studentName.Length > 5
                                       orderby c.studentName.Length
                                       select c.studentName.ToUpper();
            foreach (string name in query)
            {

            }
            //var q = from a in ADB.GetTable<student>()
            //       select a;
            //dtStudents = LinqQuerytoDataTable(q);
            //var q1 = from a in ADB.GetTable<aClass>()
            //         select a;
            //aClass c = new aClass();

            //dtClasses = reformatDataTable(q1);
        }

I receive the following when I try to get information from the database at (foreach (string name in query))当我尝试从数据库中获取信息时收到以下信息 (foreach (string name in query))

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll System.Data.dll 中发生类型为“System.Data.SqlClient.SqlException”的未处理异常

Additional information: Invalid object name 'student'.附加信息:无效的对象名称“学生”。

I also get this when I first create the database:当我第一次创建数据库时,我也得到了这个:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.Linq.dll System.Data.Linq.dll 中发生类型为“System.InvalidOperationException”的未处理异常

Additional information: Unable to determine SQL type for 'System.Collections.Generic.List`1[WindowsFormsApplication1.Form1+grades]'.附加信息:无法确定“System.Collections.Generic.List`1[WindowsFormsApplication1.Form1+grades]”的 SQL 类型。

remove the word Name that is what worked for me删除对我有用的单词 Name

[Table("student")]
public class student

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM