我有一个表emp2,其中包含Empid EmpName Salary
我从emp中的c传递了一个linq,其中empname ==“ss”选择c 现在我想展示那个empname的empid 但是代码在linq处显示错误 ERROR ::: Emp2.EmpName'没有支持的SQL转换。在 countrylist = query.tolist();
私有const字符串ConnectionString =“isostore:/Emp1.sdf”;
[Table(Name = "Emp")]
public class Emp2
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int EmpId
{
get;
set;
}
public string EmpName
{
get;
set;
}
public int Salary
{
get;
set;
}
}
public MainPage()
{
InitializeComponent();
using (CountryDataContext context = new CountryDataContext(ConnectionString))
{
if (!context.DatabaseExists())
{
context.CreateDatabase();
}
else
{
MessageBox.Show("Employee table exist already");
}
}
}
private IList<Emp2> getcountry()
{
IList<Emp2> countryList = null;
using (CountryDataContext context = new CountryDataContext(ConnectionString))
{
IQueryable<Emp2> query = from c in context.Emp where c.EmpName=="ss" select c;
countryList = query.ToList();
}
return countryList;
}
public class CountryDataContext : DataContext
{
public CountryDataContext(string connectionString)
: base(connectionString)
{
}
public Table<Emp2> Emp
{
get
{
return this.GetTable<Emp2>();
}
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
IList<Emp2> emp= this.getcountry();
foreach (Emp2 a in emp)
{
MessageBox.Show(a.EmpId.ToString());
}
答案 0 :(得分:1)
您尚未向EmpName
属性添加属性以指示它是列。