Linq to sql Linq强类型datacontext将不会编译
我正在尝试使用强类型LINQ to SQL datacontext从SQL Server表中获取所有数据,如以下MSDN示例所示: 我的代码如下:Linq to sql Linq强类型datacontext将不会编译,linq-to-sql,datacontext,Linq To Sql,Datacontext,我正在尝试使用强类型LINQ to SQL datacontext从SQL Server表中获取所有数据,如以下MSDN示例所示: 我的代码如下: public class bioAppointments { string _strConnString = "Data Source=local; Initial Catalog=MyDatabase; User Id=MyUser; Password=MyPassword;"; public Li
public class bioAppointments
{
string _strConnString = "Data Source=local; Initial Catalog=MyDatabase; User Id=MyUser; Password=MyPassword;";
public List<Appointment> getAllAppointments()
{
SqlConnection connection = new SqlConnection(_strConnString);
Appt dc = new Appt(connection);
var query =
from appt in dc.myAppointments
select new Appointment
{
AppointmentId = appt.AppointmentId,
StartDate = appt.StartDate,
EndDate = appt.EndDate,
StartTime = appt.StartTime,
EndTime = appt.EndTime,
Notes = appt.Notes,
};
return query.ToList();
}
public partial class Appt : DataContext
{
public Table<Appointments> myAppointments;
public Appt(string connection) : base(connection) { }
}
public class Appointment
{
public int AppointmentId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public String Notes { get; set; }
}
}
公共级生物制剂
{
string _strConnString=“数据源=本地;初始目录=MyDatabase;用户Id=MyUser;密码=MyPassword;”;
公共列表GetAllAppoints()
{
SqlConnection=newsqlconnection(\u strConnString);
Appt dc=新的Appt(连接);
变量查询=
从dc.myAppoints中的appt
选择新约会
{
AppointmentId=appt.AppointmentId,
StartDate=应用程序StartDate,
EndDate=appt.EndDate,
StartTime=appt.StartTime,
EndTime=appt.EndTime,
注释=附件注释,
};
返回query.ToList();
}
公共部分类Appt:DataContext
{
公开会议任命;
公共应用程序(字符串连接):基(连接){}
}
公开课任命
{
公共指定ID{get;set;}
公共日期时间起始日期{get;set;}
公共日期时间结束日期{get;set;}
公共日期时间开始时间{get;set;}
公共日期时间结束时间{get;set;}
公共字符串注释{get;set;}
}
}
我收到一个编译错误:
找不到类型或命名空间名称“约会”(是否缺少using指令或程序集引用?)
在Appt类中,squiggle在下面
有人知道这是什么意思吗?我如何修复它?而不是:
public Table<Appointments> myAppointments;
公共表myappoints;
不应该是这样吗?(单数)
公共表myappoints;
是的,应该是这样。默认情况下,ORM对单个对象的表名进行反复数+1.
public Table<Appointment> myAppointments;