无法使用 EntityFramework.IBM.DB2 连接到 Informix
Unable to connect to Informix using EntityFramework.IBM.DB2
我在使用 EntityFramework.IBM.DB2 (v6.0.3) 包从 .Net 4.5.2 应用程序连接到 Informix 数据库时遇到问题。当我尝试查询数据库时,我不断收到以下错误:
System.NotSupportedException : There is no store type corresponding to
the EDM type 'Edm.String' of primitive type 'String'.
报错的行是:
var existing = db
.MyEntities
.FirstOrDefault(e => e.IdB == myId);
实体本身:
public class MyEntity
{
public long IdA { get; set; }
public long IdB { get; set; }
public string NameA { get; set; }
public string NameB { get; set; }
public ICollection<OtherEntity> OtherEntities { get; set; }
}
以及用于创建 table 的脚本:
create table myentity (
idA BIGINT not null,
idB BIGINT not null,
nameA NVARCHAR(200) not null,
nameB NVARCHAR(200) not null
)
extent size 32 next size 32
lock mode page;
alter table myentity add constraint primary key
(idB)
constraint pk_myentity;
table配置:
public class MyEntityConfig : EntityTypeConfiguration<MyEntity>
{
public EventTypeConfig()
{
ToTable("MyEntity");
HasKey(u => u.IdB);
Property(u => u.IdB).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(s => s.IdA).IsRequired();
Property(s => s.NameA).IsRequired().HasMaxLength(200);
Property(s => s.NameB).IsRequired().HasMaxLength(200);
HasOptional(e => e.OtherEntities);
HasMany(e => e.OtherEntities);
}
}
当我 运行 testconn40
我通过了测试,所以我不认为这是连接到数据库的问题。我有另一个项目使用非常相似的设置,所以我不知道出了什么问题。
非常感谢任何人就此特定错误提供的任何帮助或信息。
EF 支持仅通过使用 IBM DB2 客户端驱动程序。
由于 IBM DB2 客户端驱动程序使用 DRDA 协议,因此您
需要使用 IDS 服务器启用 DRDA 端口,然后它应该可以工作。
IBM DB2 客户端团队在 developerworks 论坛上更加活跃。
如果您仍然遇到问题,可以通过 developerworks 重新发布,url 是
此错误是由于 .Net 类型映射到数据库类型的方式所致。
我的一个数据库表中有一个类型为 LVARCHAR(32000)
的字段,而我实体上的相应字段是 string
。我将数据库中的字段更新为 NCHAR(32000)
并将以下内容添加到我的实体配置 class:
Property(s => s.StringProp).HasMaxLength(32000).IsRequired();
进行这些更改后,错误就消失了。
我遇到的另一个奇怪的错误是:
System.NotSupportedException : There is no store type corresponding to
the EDM type 'Edm.Guid' of primitive type 'Guid'.
Informix 似乎不支持 Guid 类型;我在插入和检索时使用 VARCHAR(36)
并在 Guid 和字符串之间映射,所以这个错误很奇怪。事实证明这取决于我如何使用 LINQ 进行查询。
这一行抛出错误:
var dbEntity = dbContext
.MyEntities
.FirstOrDefault(e => e.Id == myGuid.ToString());
哪里可以正常工作:
var id = myGuid.ToString();
var dbEntity = dbContext
.MyEntities
.FirstOrDefault(e => e.Id == id);
基本上我发现的是,当您尝试使用 EntityFramework.IBM.DB2
做任何事情时,您必须尽可能保持一切简单明了,否则您将继续 运行 陷入神秘的错误在网上几乎找不到支持。
希望这对以后的人有所帮助。
我在使用 EntityFramework.IBM.DB2 (v6.0.3) 包从 .Net 4.5.2 应用程序连接到 Informix 数据库时遇到问题。当我尝试查询数据库时,我不断收到以下错误:
System.NotSupportedException : There is no store type corresponding to the EDM type 'Edm.String' of primitive type 'String'.
报错的行是:
var existing = db
.MyEntities
.FirstOrDefault(e => e.IdB == myId);
实体本身:
public class MyEntity
{
public long IdA { get; set; }
public long IdB { get; set; }
public string NameA { get; set; }
public string NameB { get; set; }
public ICollection<OtherEntity> OtherEntities { get; set; }
}
以及用于创建 table 的脚本:
create table myentity (
idA BIGINT not null,
idB BIGINT not null,
nameA NVARCHAR(200) not null,
nameB NVARCHAR(200) not null
)
extent size 32 next size 32
lock mode page;
alter table myentity add constraint primary key
(idB)
constraint pk_myentity;
table配置:
public class MyEntityConfig : EntityTypeConfiguration<MyEntity>
{
public EventTypeConfig()
{
ToTable("MyEntity");
HasKey(u => u.IdB);
Property(u => u.IdB).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(s => s.IdA).IsRequired();
Property(s => s.NameA).IsRequired().HasMaxLength(200);
Property(s => s.NameB).IsRequired().HasMaxLength(200);
HasOptional(e => e.OtherEntities);
HasMany(e => e.OtherEntities);
}
}
当我 运行 testconn40
我通过了测试,所以我不认为这是连接到数据库的问题。我有另一个项目使用非常相似的设置,所以我不知道出了什么问题。
非常感谢任何人就此特定错误提供的任何帮助或信息。
EF 支持仅通过使用 IBM DB2 客户端驱动程序。 由于 IBM DB2 客户端驱动程序使用 DRDA 协议,因此您 需要使用 IDS 服务器启用 DRDA 端口,然后它应该可以工作。
IBM DB2 客户端团队在 developerworks 论坛上更加活跃。 如果您仍然遇到问题,可以通过 developerworks 重新发布,url 是
此错误是由于 .Net 类型映射到数据库类型的方式所致。
我的一个数据库表中有一个类型为 LVARCHAR(32000)
的字段,而我实体上的相应字段是 string
。我将数据库中的字段更新为 NCHAR(32000)
并将以下内容添加到我的实体配置 class:
Property(s => s.StringProp).HasMaxLength(32000).IsRequired();
进行这些更改后,错误就消失了。
我遇到的另一个奇怪的错误是:
System.NotSupportedException : There is no store type corresponding to the EDM type 'Edm.Guid' of primitive type 'Guid'.
Informix 似乎不支持 Guid 类型;我在插入和检索时使用 VARCHAR(36)
并在 Guid 和字符串之间映射,所以这个错误很奇怪。事实证明这取决于我如何使用 LINQ 进行查询。
这一行抛出错误:
var dbEntity = dbContext
.MyEntities
.FirstOrDefault(e => e.Id == myGuid.ToString());
哪里可以正常工作:
var id = myGuid.ToString();
var dbEntity = dbContext
.MyEntities
.FirstOrDefault(e => e.Id == id);
基本上我发现的是,当您尝试使用 EntityFramework.IBM.DB2
做任何事情时,您必须尽可能保持一切简单明了,否则您将继续 运行 陷入神秘的错误在网上几乎找不到支持。
希望这对以后的人有所帮助。