c# - 如何使用 Windows Phone 8 中的属性在 SQLite 中创建多个表

标签 c# sqlite windows-phone-8

如何使用实体类创建多个表

public class Info
    {
        public string firstName { get; set; }
        public string lastName { get; set; }
        public string imageUrl { get; set; }
         [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
         public DetailInfo objDetailInfo{ get; set; }
    }

    public class DetailInfo
    {
        public string phoneno { get; set; }
        public string address { get; set; }
    }

我正在使用下面的代码
public void createtable()
{
  SQLite.SQLiteConnection db= new SQLite.SQLiteConnection(dbPath);
   db.CreateTable<Info>();
   var data = new Info() { Id = "1", firstName = "Rehan", imageUrl = "safsdfsdf", lastName = "Parvez", objsty = new objDetailInfo{ address = "Nagpur", phoneno = "902136" } };
   db.Insert(data);   

 }

在执行 db.CreateTable<Info>()它给了我一个错误

最佳答案

我自己回答我的问题,因为我认为这会对我的其他 friend 有所帮助
使用忽略关键字

public class Info
{
    public string firstName { get; set; }
    public string lastName { get; set; }
    public string imageUrl { get; set; }
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [Ignore]
    public DetailInfo objDetailInfo{ get; set; }
}

public class DetailInfo
{
    public string phoneno { get; set; }
    public string address { get; set; }
}

public void createtable()
{
   SQLite.SQLiteConnection db= new SQLite.SQLiteConnection(dbPath);
   db.CreateTable<Info>();
   db.CreateTable<DetailInfo>();
}

关于c# - 如何使用 Windows Phone 8 中的属性在 SQLite 中创建多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21478830/

相关文章:

C# 按名称中的自然数顺序对文件进行排序?

php - 具有外键支持的 SQLite Android 表和上传到远程服务器不起作用

android - 在不同的 SQLiteOpenHelper 实例中使用相同的 SQLiteDatabase 实例

sqlite.cs 找不到 sqlite3 和社区

c# - 多层架构和身份。为什么要使用UserManager和RoleManager?

c# - C#异步调用同步服务调用的策略

c# - 'void' 没有重载匹配委托(delegate) 'ThreadStart'

ruby-on-rails-3 - 测试环境中的 Rails 3 不允许保存记录,即使使用最新的 sqlite3

c# - 错误 : GenerateWinPRTManifest

c# - C#编写的类库如何引用C++编写的Windows运行时组件?