gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:54:12 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com