首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wp7数据连接错误

Wp7数据连接错误
EN

Stack Overflow用户
提问于 2012-05-11 16:54:22
回答 1查看 103关注 0票数 0

我有一个包含Empid EmpName薪水的表emp2

我在emp的empname=="ss“select c中传递了一个linq,现在我想显示该empname的empid,但代码在linq error : Emp2.EmpName‘没有支持到SQL的转换。在countrylist=query.tolist();

私有常量字符串ConnectionString = "isostore:/Emp1.sdf";

代码语言:javascript
复制
    [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());

        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-11 17:43:57

您尚未向EmpName属性添加属性以指示它是一个列。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10548346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档