Last active
March 13, 2022 15:41
-
-
Save shahabganji/7bdd7fe3adf40365c4567bbd4139db5e to your computer and use it in GitHub Desktop.
EfCore-Array-Of-String-Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Book | |
{ | |
private List<string> _tags; | |
private Book() | |
{ | |
_tags = new List<string>(); | |
} | |
public Book(string name) | |
{ | |
Id = Guid.NewGuid(); | |
Name = name; | |
_tags = new List<string>(); | |
} | |
public Guid Id { get; } | |
public string Name { get; } | |
public IReadOnlyCollection<string> Tags => _tags.AsReadOnly(); | |
public void AddTag(params string[] tags) => _tags = new List<string>(_tags.Union(tags)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Microsoft.EntityFrameworkCore.Metadata.Builders; | |
using Sample.EFCore.ArrayPrimitiveTypes.Domain; | |
using Sample.EFCore.ArrayPrimitiveTypes.Storage.Converters; | |
namespace Sample.EFCore.ArrayPrimitiveTypes.Storage.Configurations; | |
public sealed class BookConfiguration : IEntityTypeConfiguration<Book> | |
{ | |
public void Configure(EntityTypeBuilder<Book> builder) | |
{ | |
builder.ToContainer("Books"); | |
builder.HasKey(p => p.Id); | |
builder.HasPartitionKey(p => p.Id); | |
builder.Property(p => p.Id) | |
.ToJsonProperty("id") | |
.IsRequired(); | |
builder.Property(p => p.Name).IsRequired(); | |
builder.Property(p => p.Tags) | |
.HasConversion<TagsValueConverter>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unhandled exception. System.InvalidOperationException: The property 'Book.Tags' is of type 'IReadOnlyCollection<string>' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. | |
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidatePropertyMapping(IModel model, IDiagnosticsLogger`1 logger) | |
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger) | |
at Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal.CosmosModelValidator.Validate(IModel model, IDiagnosticsLogger`1 logger) | |
at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger) | |
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime) | |
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime) | |
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() | |
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p) | |
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context) | |
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) | |
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment