Windows phone 7 简单linq到sql查询异常

Windows phone 7 简单linq到sql查询异常,windows-phone-7,linq-to-sql,Windows Phone 7,Linq To Sql,我第一次在电话上玩LinqtoSQL。我创建了一个简单的类,但是除了基本的选择查询之外的任何查询,例如“from p in db.Icons select p”都会抛出一个异常 var q = from p in db.Icons where p.Name == "testa" select p; // ^ Throws 'The member Icon.Name has no supported t

我第一次在电话上玩LinqtoSQL。我创建了一个简单的类,但是除了基本的选择查询之外的任何查询,例如“from p in db.Icons select p”都会抛出一个异常

        var q = from p in db.Icons
                where p.Name == "testa"
                select p;
        // ^ Throws 'The member Icon.Name has no supported translation to SQL'
除了下面粘贴的源代码中的异常原因之外,我还有两个问题:

[Column]
private bool _isFavourite = false; // Does this actually set a default value?
                                   // Should I use Nullable<T> for value types?
                                   // i.e. should this be 'bool?' instead.

您没有名为
Name
并标记为
[Column]
的属性,因此出现异常不应感到意外。用
[Column]
而不是字段标记您的属性,它应该可以工作


您应该阅读WP7 SQL CE系列:

您没有名为
Name
并标记为
[Column]
的属性,因此出现异常不应感到意外。用
[Column]
而不是字段标记您的属性,它应该可以工作


您应该阅读WP7 SQL CE系列:

啊,谢谢。我从一本书中获取了代码,它就是这样写的。我认为这是正确的-什么都不能相信:)啊,谢谢。我从一本书中获取了代码,它就是这样写的。我认为这是正确的-不能相信任何事情:)
public Table<Icon> Icons
{
    get // Is this getter necessary? Wouldn't 'Table<Icon> Icons' suffice?
    {
        return this.GetTable<Icon>();
    }
}
    //Icon.cs
    [Table]
    public class Icon : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private const string IdPropertyName = "Id";
        private const string NamePropertyName = "Name";
        private const string IsFavouritePropertyName = "IsFavourite";
        private const string IconUrlPropertyName = "IconUrl";

        [Column(IsPrimaryKey=true, IsDbGenerated=true)]
        private int _id;
        [Column]
        private string _name;
        [Column]
        private bool _isFavourite = false; // Does this actually set a default value?
                                           // Should I use Nullable<T> for value types?
                                           // i.e. should this be 'bool?' instead.
        [Column]
        private string _iconUrl; 


        public int Id
        {
            get
            {
                return _id;
            }

            set
            {
                RaisePropertyChanging(IdPropertyName);
                _id = value;
                RaisePropertyChanged(IdPropertyName);
            }
        }

        public string Name
        {
            get
            {
                return _name;
            }

            set
            {
                RaisePropertyChanging(NamePropertyName);
                _name = value;
                RaisePropertyChanged(NamePropertyName);
            }
        }

        public bool IsFavourite
        {
            get
            {
                return _isFavourite;
            }

            set
            {
                RaisePropertyChanging(IsFavouritePropertyName);
                _isFavourite = value;
                RaisePropertyChanged(IsFavouritePropertyName);
            }
        }

        public string IconUrl
        {
            get
            {
                return _iconUrl;
            }

            set
            {
                RaisePropertyChanging(IconUrlPropertyName);
                _iconUrl = value;
                RaisePropertyChanged(IconUrlPropertyName);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;
        public void RaisePropertyChanging(string propertyName)
        {
            PropertyChangingEventHandler handler = PropertyChanging;
            if (handler != null)
            {
                handler(this, new PropertyChangingEventArgs(propertyName));
            }
        }

    }
//IconsManagerContext.cs
public class IconsManagerContext : DataContext
{

    public Table<Icon> Icons
    {
        get // Is this getter necessary? Wouldn't 'Table<Icon> Icons' suffice?
        {
            return this.GetTable<Icon>();
        }
    }

    private const string DbConnectionString = @"DataSource=isostore:/IconsManager.sdf";
    public IconsManagerContext()
        : this(DbConnectionString)
    {

    }

    public IconsManagerContext(string connectionString)
        : base(connectionString)
    {
        if (!DatabaseExists())
        {
            CreateDatabase();
            Icons.InsertAllOnSubmit<Icon>(new List<Icon>()
            { 
             new Icon() { 
                 IconUrl="/Images/testa.jpg",
                 Name="Testa",
                 IsFavourite=true
             },
             new Icon() { 
                 IconUrl="/Images/testb.jpg",
                 Name="Testb",
             }
            this.SubmitChanges();
        }
    }
}
//MainPage.xaml
 public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        using (var db = new IconsManagerContext())
        {
            var q = from p in db.Icons
                    where p.Name == "testa"
                    select p;
            // ^ Throws 'The member Icon.Name has no supported translation to SQL'

            IconsListBox.ItemsSource = q;
        }; 
    }
}