Windows Phone 8 - исключение при отправке изменений

У меня проблема с локальной базой данных в приложении Windows Phone 8.

Это мой DatabaseManager и модели

 public class DatabaseManager : DataContext
{
    // Specify the connection string as a static, used in main page and app.xaml.
    public static string DBConnectionString = "Data Source=isostore:/LocalMainDatabase.sdf";

    // Pass the connection string to the base class.
    public DatabaseManager(string connectionString) : base(connectionString) { }

    // Specify a single table for the to-do items.
    //public Table<GroupDatabaseModel> GroupDbModel;
    public Table<GroupDatabaseModel> GroupDbModel;
}




[Table]
public class GroupDatabaseModel : INotifyPropertyChanged, INotifyPropertyChanging
{
    private int id;
    //private string name { get; set; }


    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int Id
    {
        get
        {
            return id;
        }
        set
        {
            if (id != value)
            {
                NotifyPropertyChanging("Id");
                id = value;
                NotifyPropertyChanged("Id");
            }
        }
    }


    /*[Column(IsPrimaryKey = false, IsDbGenerated = true, DbType = "NVarChar(30) NOT NULL", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            if (name != value)
            {
                NotifyPropertyChanging("Name");
                name = value;
                NotifyPropertyChanged("Name");
            }
        }
    }*/


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



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

}

В моей ViewModel я создаю базу данных

DatabaseManager db;
        using (db = new DatabaseManager("isostore:/LocalMainDatabase.sdf"))
        {
            if (db.DatabaseExists() == false)
            {
                // Create the database.
                db.CreateDatabase();



                GroupDatabaseModel k1 = new GroupDatabaseModel { Id = 11 }; 



                db.GroupDbModel.InsertOnSubmit(k1);


                try
                {
                    db.SubmitChanges();
                }
                catch (Exception exx)
                {
                    //  Console.WriteLine(exx);
                    // Make some adjustments. 
                    // ... 
                    // Try again.
                    db.SubmitChanges();
                }

                // Define query to gather all of the to-do items.
                var toDoItemsInDB = from GroupDatabaseModel todo in db.GroupDbModel select todo;

К сожалению, я получаю исключение при отправке изменений:

"Исключение типа 'System.NotSupportedException' произошло в System.Data.Linq.ni.dll, но не было обработано в коде пользователя

Дополнительная информация: вставка строки, состоящей только из значений, сгенерированных базой данных, в этом поставщике данных не поддерживается."

Что случилось?

0 ответов

Другие вопросы по тегам