Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NHibernate字典:无法初始化集合_C#_Sqlite_Nhibernate_Dictionary - Fatal编程技术网

C# NHibernate字典:无法初始化集合

C# NHibernate字典:无法初始化集合,c#,sqlite,nhibernate,dictionary,C#,Sqlite,Nhibernate,Dictionary,我班上有一本字典 public class AffectedVehicleInScenario : DomainObjectWithId { ... some other properties ... private readonly int _id; private readonly IDictionary<int, int> _installationRates = new Dictionary<int, int>();

我班上有一本字典

public class AffectedVehicleInScenario : DomainObjectWithId {

    ... some other properties ...

    private readonly int _id;
    private readonly IDictionary<int, int> _installationRates
        = new Dictionary<int, int>();

    ... some code ...

}
有人能帮帮我吗?映射是不正确的还是nhibernate中的错误

提前谢谢

托比

更新: 创建的表如下所示:

CREATE TABLE tblInstallationRatesOfAffectedVehicleInScenario
(
    AffectedVehicleInScenarioId INT not null,
    InstallationRate SMALLINT not null,
    Year INT not null,
    primary key (AffectedVehicleInScenarioId, Year),
    constraint FKDF60481555A07D7C foreign key (AffectedVehicleInScenarioId) references tblAffectedVehicleInScenario
)

我猜这是因为sqlite驱动程序返回一个短框as对象,该对象不能直接转换为int。您可以使用
IDictionary
或使用ImplementiuserType,或者可能有一些配置告诉NH区别。

看起来列类型不是要转换的整数me@Firo:我添加了用于创建已用表格的脚本,对吗也更改为
(让NHibernate猜一下类型)?如果我省略了元素的类型定义(dictionary的值),它可以正常工作。多谢。
Spring.Data.NHibernate.HibernateSystemException: could not initialize a collection:
[Com.QueoMedia.CO2Simulationstool.Domain.AffectedVehicleInScenario._installationRates#1][SQL: SELECT installat0_.AffectedVehicleInScenarioId as Affected1_0_, installat0_.InstallationRate as Installa2_0_, installat0_.Year as Year0_ FROM tblInstallationRatesOfAffectedVehicleInScenario installat0_ WHERE installat0_.AffectedVehicleInScenarioId=?]
---> NHibernate.Exceptions.GenericADOException: could not initialize a collection:
[Com.QueoMedia.CO2Simulationstool.Domain.AffectedVehicleInScenario._installationRates#1][SQL: SELECT installat0_.AffectedVehicleInScenarioId as Affected1_0_, installat0_.InstallationRate as Installa2_0_, installat0_.Year as Year0_ FROM tblInstallationRatesOfAffectedVehicleInScenario installat0_ WHERE installat0_.AffectedVehicleInScenarioId=?]
---> System.InvalidCastException: Die angegebene Umwandlung ist ungültig.
CREATE TABLE tblInstallationRatesOfAffectedVehicleInScenario
(
    AffectedVehicleInScenarioId INT not null,
    InstallationRate SMALLINT not null,
    Year INT not null,
    primary key (AffectedVehicleInScenarioId, Year),
    constraint FKDF60481555A07D7C foreign key (AffectedVehicleInScenarioId) references tblAffectedVehicleInScenario
)