ManyToOne关系上的Xamarin.Forms Sqlite-net NotSupportedException“不知道<model>” - c#

我在xamarin.forms应用程序中使用sqlite net扩展库。我在PCL中编写数据库代码和模型。

当我调用SQLiteConnection.CreateTable()时出现错误
System.NotSupportedException: Don't know about Cigars.Models.Cigar

Smoke是雪茄的孩子,它与ManyToOne有关系。
这些是模型:

抽烟

public class Smoke
{

    [PrimaryKey]
    public int SmokeId { get; set; }

    [ForeignKey(typeof(Cigar))]
    public int CigarId { get; set; }

    public string Notes { get; set; }

    public DateTime DateCreated { get; set; }

    //why is this not recognized?
    [ManyToOne]
    public Cigar Cigar { get; set; }

}

雪茄

public class Cigar
{

    [PrimaryKey]
    public int CigarId { get; set; }

    public string Name { get; set; }

    public double Length { get; set; }
}

我的数据库调用导致引发异常:

private SQLiteConnection db;

public Database(string path)
{
    db = new SQLiteConnection(path);
    db.CreateTable<Cigar>();
    db.CreateTable<Smoke>(); //this throws the error
}

参考方案

问题是我为sqlite安装了两个不同的库,都包含一个SQLiteConnection

我需要将Sqlite.Net.SQLiteConnection类用于sqlite网络扩展。不是我使用的Sqlite.SQLiteConnection

正如SushiHangover指出的那样,此Sqlite.Net.SQLiteConnection采用类型为ISQLitePlatform的第一个参数。

为了获得对此的参考,我定义了一个接口,该接口提供了返回ISQLitePlatform的方法的签名:

public interface ISQLitePlatformInstance
{
    ISQLitePlatform GetSQLitePlatformInstance();
}

我在Droid项目(我要建立的平台)中实现了该接口:

public class SQLitePlatformInstance : ISQLitePlatformInstance
{

    public ISQLitePlatform GetSQLitePlatformInstance()
    {
        return new SQLitePlatformAndroid();
    }

}

将列表<>写入数据库asp.net - c#

我被困写数据库不要把我丢错写命令不起作用控制器:[HttpPost] public async Task<ActionResult>PartialTabelaEcp(string userDate) { var numerMiesiaca = 1; var numerRoku = 1; var dbExists = _ecpContext.Kar…

休眠映射<键,设置<值>> - java

我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …

如何使用BeautifulSoup在<tr>中捕获特定的<td> - python

尝试从nyc Wiki页面中的高中列表中获取所有高中名称。我已经写了足够多的脚本,可以让我获取包含在高中,学业和入学条件列表的表的<tr>标记中的所有信息-但是我如何才能缩小到我认为的范围内在td[0]内休息(会弹出KeyError)-只是学校的名称?到目前为止我写的代码:from bs4 import BeautifulSoup from ur…

使用Google地图获取到最近的地标(购物中心,医院和机场等)的距离 - java

Improve this question 我正在做一个项目,在印度的主要城市中,我有大约100000个地址(这是数据库中的表格)。我想知道是否可以获取到最近的地标(购物中心,医院和机场等)的距离。理想情况下,我希望将这些距离合并到父表中。一旦找到解决方法,我们就会有Java和Php编码器来完成它。任何指针都会有很大帮助。谢谢。 参考方案 (我可能会在这里说…

合并List <T>和List <Optional <T >> - java

鉴于: List<Integer> integers = new ArrayList<>(Arrays.asList( 10, 12 )); List<Optional<Integer>> optionalIntegers = Arrays.asList( Optional.of(5), Optional.em…