Add new table to database

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Running the code should create the table in the database
3 years ago
Hi I'm working with nopcommerce 4.2 I'm trying to add a new entity, I created the Entity and Map classes but i'm having this error:
InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)

DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = CatalogSettings (DelegateActivator), Services = [Nop.Core.Domain.Catalog.CatalogSettings], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext. (See inner exception for details.)
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable<Parameter> parameters, out object decoratorTarget)

DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = PluginService (ReflectionActivator), Services = [Nop.Services.Plugins.IPluginService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = CatalogSettings (DelegateActivator), Services = [Nop.Core.Domain.Catalog.CatalogSettings], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext. (See inner exception for details.) (See inner exception for details.)
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable<Parameter> parameters, out object decoratorTarget)

TargetInvocationException: Exception has been thrown by the target of an invocation.
System.RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapExceptions)

CustomAttributeFormatException: 'Policy' property specified was not found.
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount, RuntimeType attributeFilterType, bool mustBeInheritable, IList derivedAttributes)


Please what i'm missing? or is not recomdable add entities directly to nopcommerce core?
thanks
3 years ago
CustomAttributeFormatException: 'Policy' property specified was not found.

Possibly have you decorated a property on your data model with an attribute, and the  formatting is not quite right.
3 years ago
Also check your DependencyRegistrar.cs if you miss to add your context in dependenacy registrar.
3 years ago
JonQuick wrote:
CustomAttributeFormatException: 'Policy' property specified was not found.

Possibly have you decorated a property on your data model with an attribute, and the  formatting is not quite right.


Thank you very much, you right!
3 years ago
forefront wrote:
I have a problem. I must add new table to database.
Where I must add new classes ?
How to Re-create new database?

This is the process to create entity in nopCommerce

Create Table Class in Nop.Core
Create Mapping in Nop.Data
Create Services and Interface for Data manipulation in Nop.Service
Create Controller/Models in Nop.Web or Nop.Admin for Execute service methods and pass data to view using model.
Create View in in Nop.Web or Nop.Admin for UI

Delete Settings.txt from App_Data folder and run project again.

Thanks,
Jatin


one most important thing you've to register services in dependency regitrar in web framework. also if you've model factories, do same. And finally no need to delete settings.txt if you have connected local database.
3 years ago
Hi:  

Just to clarify, is this approach meant to bypass nopCommerce's code-first approach using Linq2DB and FluentMigrator?

nopCommerce's code-first info:
https://docs.nopcommerce.com/en/developer/tutorials/data-access-layer.html#:~:text=nopCommerce%20uses%20the%20Linq2DB%20Code,are%20defined%20in%20the%20Nop.&text=That%27s%20why%20it%27s%20called%20Code,is%20executed%20against%20the%20database
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.