Code Monkey home page Code Monkey logo

wilcommerce.catalog.data.efcore's Introduction

Wilcommerce.Catalog.Data.EFCore

Contains an implementation of Wilcommerce.Catalog package using Entity Framework Core as persistence framework.

Requirements

According to Entity Framework Core 3.1 requirements, this project is built using NETStandard 2.1 as Target Framework (See https://docs.microsoft.com/it-it/ef/core/what-is-new/ef-core-3.0/breaking-changes#netstandard21 for further informations).

This means it will not run on projects which target .NET Framework.

If you have some specific needs you can open a issue on GitHub or you can consider to contribute to Wilcommerce.

Installation

Nuget package available here

https://www.nuget.org/packages/Wilcommerce.Catalog.Data.EFCore/

Usage

Add the CatalogContext class to your project.

For example in an ASP.NET Core project add this line to the ConfigureServices method in Startup.cs

services.AddDbContext<CatalogContext>(options => // Specify your provider);

The CatalogContext is injected in the read model component and the Repository implementation.

After the DbContext has been registered in the ServiceCollection, you need to add a migration using donet CLI or the Package Manager Console.

// Using dotnet CLI
dotnet ef migrations add -c Wilcommerce.Catalog.Data.EFCore.CatalogContext Initial

// Using Package Manager Console
EntityFrameworkCore\Add-Migration -Context Wilcommerce.Catalog.Data.EFCore.CatalogContext Initial

After this, you can update your database:

// Using dotnet CLI
dotnet ef database update -c Wilcommerce.Catalog.Data.EFCore.CatalogContext

// Using Package Manager Console
EntityFrameworkCore\Update-Database -Context Wilcommerce.Catalog.Data.EFCore.CatalogContext

Read model Component

The CatalogDatabase class is the implementation of the ICatalogDatabase interface.

It provides a facade to access all the readonly data. It requires an instance of CatalogContext as constructor parameters.

Repository Component

The Repository class is the implementation of the IRepository interface.

It provides all the methods useful for persist an Aggregate model. It requires a CatalogContext instance as constructor parameter.

Contributing

If you want to contribute to Wilcommerce please, check the CONTRIBUTING file.

wilcommerce.catalog.data.efcore's People

Contributors

albx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

4bitsteams

wilcommerce.catalog.data.efcore's Issues

Persisting new related entity to existing object throws an exception

When a new related entity is added to an existing one, Entity Framework Core will throw a DbUpdateConcurrencyException saving all the changes.

This error happens because the Id of the entities is explicitly generated in code and should be fixed adding this instruction:

modelBuilder.Entity<T>().Property(e => e.Id).ValueGeneratedNever()

see dotnet/efcore#20650 for further information

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.