[英]Filter integer array of jsonb column in postgres using EF Core and NpgSql
[英]Npgsql / EF 6 - json column
我正在尝试使用JSON列创建迁移。 这是我试过的:
[Column(TypeName = "Jsonb")]
public string Data { get; set; }
[Column(TypeName = "Json")]
public string Data { get; set; }
modelBuilder.Entity<Member>().Property(p => p.Data).HasColumnType("Json");
modelBuilder.Entity<Member>().Property(p => p.Data).HasColumnType("Jsonb");
什么都没有,这是例外:
System.InvalidOperationException:Sequence在系统中System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest,String name)的System.Linq.Enumerable.Single [TSource](IEnumerable
1 source, Func
2谓词)中不包含匹配元素System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty列,EntityType表)中的.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty列,EntityType表,DbProviderManifest providerManifest) ,System.Data.Entity.UnumerableExtensions.Each中的System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration。<> c__DisplayClass4.b__3(元组2 pm) at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable
DbProviderManifest providerManifest,Boolean allowOverride,Boolean fillFromExistingConfiguration)1 action) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable
2 pm) at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable
1 ts,Action1 action) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable
1 action) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable
1个propertyMappings,DbProviderManifest providerManifest,布尔有的allowOverride,布尔fillFromExistingConfiguration)在System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList的1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride) at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride) at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, ICollection
1 entitySets) ,DbProviderManifest providerManifest)位于System.Data.Entity.DbModelBuilder的System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest,DbProviderInfo providerInfo)的System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping,DbProviderManifest providerManifest) .Build(DbConnection providerConnection)在System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)的System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
InitializeContext()在System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() at System.Data.Entity.Internal.Linq.InternalSet
Initialize()1.get_InternalContext() at System.Data.Entity.Internal.Linq.InternalSet
System_Data.Entity.Internal.Linq.InternalSet 1.get_Local()中的1.get_InternalContext() at System.Data.Entity.Internal.Linq.InternalSet
中的System.Data.Entity.DbSet`1.get_Local()。 gisterUserAccountChildTablesForDelete [TKey,TAccount,TUserClaim,TLinkedAccount,TLinkedAccountClaim,TPasswordResetSecret,TTwoFactorAuthToken,TUserCertificate](DbContext ctx)在c:\\ ballen \\ github \\ brockallen \\ BrockAllen.MembershipReboot \\ src \\ BrockAllen.MembershipReboot.Ef \\ DbModelBuilderExtensions.cs:第26行
这是我的配置:
<package id="EntityFramework" version="6.1.1" targetFramework="net452" />
<package id="EntityFramework6.Npgsql" version="3.1.1" targetFramework="net452" />
<package id="Npgsql" version="3.1.6" targetFramework="net452" />
因此,这是完全可行的,但需要修改生成的迁移,而不是注释模型或使用流畅的配置。 在生成的迁移中,更改data
列的声明以使用storeType
和defaultValueSql
参数:
data = c.String(nullable: false, storeType: "jsonb", defaultValueSql: "'{}'::jsonb")
我可以确认这适用于Npgsql 3.1.7与EntityFramework6.Npgsql 3.1.1,并将保存和加载适用的实体没有问题。 无法担保早期版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.