GenericRepository | SEE README ) This little project contains
kandi X-RAY | GenericRepository Summary
kandi X-RAY | GenericRepository Summary
:warning: THIS REPOSITORY IS NOT MAINTAINED ANYMORE. IF YOU WOULD LIKE TO VOLUNTEER TO BE THE MAINTAINER, PLEASE CONTACT ME. This little project contains a Generic Repository implementation for several data access platforms such as Entity Framework.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of GenericRepository
GenericRepository Key Features
GenericRepository Examples and Code Snippets
Community Discussions
Trending Discussions on GenericRepository
QUESTION
I am trying to build a lambda expression progressively in this manner:
...ANSWER
Answered 2022-Apr-02 at 22:26LINQ Expression
s are trees of objects, not collections of text to be compiled. While the parameters from the source function expressions may look the same on the outside they are in fact different objects that just happen to have the same properties. So when you combine two function expressions and throw out the parameter(s) from one of them you're left with an Expression
that doesn't have all the information.
To make this more obvious, imagine you're adding a => a.Name == "test"
to b => b.Age > 0
. Your code will produce a LINQ expression equivalent to a => a.Name == "test" && b.Age > 0
... which leaves an unknown object b
in the mix. Even if you changed the name in the source expression it would still be an unknown object.
Fortunately we can use an ExpressionVisitor
to fix this up for us. Here's one I've used in similar situations:
QUESTION
I am using .NET 5 and I want to run a background task using IHostedService
classess as you can see:
ANSWER
Answered 2022-Feb-20 at 18:32Your hosted service is singleton and you have an indirect dependency to a scoped service:
Cannot consume scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[MIMS.Portal.Infrustructure.Repositories.AppDbContext]' from singleton 'Microsoft.Extensions.Hosting.IHostedService'
You can workaround the problem in the following ways
Inject IServiceScopeFactory
into your hosted service and create the service scope manually like below
QUESTION
I am trying to implement the GenericRepository pattern for a Cosmos DB Gremlin Graph API Datasource. So I have:
- Added and verified a working Gremlin.Linq library that interfaces w/my Cosmos Graph Database.
- Know that in the Generic Repository it implements
TEntity
whereTEntity
is aclass
. I have done the same. - I am now implementing my Generic Repository and want to use a Generic Extension with a clause for a new() so I'm getting the error. What should I do?
Error The type 'typename' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'parameter' in the generic type or method 'generic'
...ANSWER
Answered 2022-Mar-25 at 22:37You are allowed to apply multiple generic constraints when defining a generic type, like so:
QUESTION
In ASP.NET Core-6 Entity Framework, I am using Generic Repository:
...ANSWER
Answered 2022-Feb-22 at 15:24The answer is on another stack exchange site: https://softwareengineering.stackexchange.com/questions/433387/whats-wrong-with-returning-null
Quote
You have enabled the nullable reference types (NRT) feature of C#. This requires you to explicitly specify when a null may be returned. So change the signature to:
QUESTION
I discovered one problem while creating my project. If someone refer to the issue I will be grateful. In my project I use a layered model. The repository layer (data access layer) that communicates with the database (DB) and the service layer (business logic layer) in which services and objects are implemented (data transfer object).
As a result, there is a problem with the dbSet.Update method. When object (obj) comes into Update method as parameter, during the method call of the _db.Entry(dbSet.Local.FirstOrDefault(i => i.Id == obj.Id) ?? obj).State = EntityState.Modified or _db.Update(dbSet.Local.FirstOrDefault(i => i.Id == obj.Id) ?? obj) in the case of the first user's update (like from "view.xaml") obj is update and changes saving in the database (because dbSet.Local.FirstOrDefault(i => i.Id == obj.Id) returns null and obviously my obj gets into the _db.Update method). In case of a repeated user's update (in the "view.xaml" view) object obj -- when it gets into the _db.Update(dbSet.Local.FirstOrDefault(i => i.Id == obj.Id) ?? obj) method, it isn't take account, as the data context already tracks it and in the _db.Update method gets an object from dbSet.Local.FirstOrDefault(i => i.Id == obj.Id). Everything would be fine if this object in dbSet.Local was updated according to the type that comes from the user. However, this is not the case, it is tracked but not changed when the user edits its properties. It is not tracked properly rather due to the fact that I use services and, accordingly, data transfer object entities.
In view of the foregoing, I have a question. How to make to update entity (by a new modified object) that are tracked, or how to manually assign the necessary object in dbSet.Local to replace the one stored there? or how to make Microsoft.EntityFrameworkCore.ChangeTracking not track changes to my objects in any way?
In order to make changes not tracked I used the QueryTrackingBehavior.NoTracking parameter for the DbContextOptionsBuilder entity, but this only helps on the first load, and tracking is still used when the data is updated further. I also used the dbSet.Local.Clear() methods, but this is a bad idea, as data updating due to the deletion of the previous data from the database (like delete 20 rows from table and add one updated).
...ANSWER
Answered 2022-Feb-16 at 18:36It's unusual to be so heavily coupled to the local cache. The normal pattern is to call DbSet.Find(id)
, and update the properties of the entity that it returns.
QUESTION
I added odata to startup and model builder and I wanted to test if it works and return an OData so I updated the controller and changed it to "ODataController" and I make a simple HttpGet test the result but the URL: Text returns 404 not found Text return 404 not found and Text return a simple Array with json objects
This is my code
Startup.cs
...ANSWER
Answered 2021-Aug-04 at 02:16I find the error, it comes from the routing rule of odata v8.
The construction of the relationship between endpoints and OData routing template is based on a set of rules, such rules are called OData Routing Convention. For example, “CustomersController” is an OData controller when the controller name “Customers” is an entity set in a given Edm model. “EntitySetName + Controller” is one of the OData controller name convention.
That means we need to make the controller name and EdmModel keep consistent. For example, here's my EdmModel setting in startup:
QUESTION
I can list and create records, but can't update the records. When I run my project and click the Edit button on listed records, form page appears, but if I click Submit after completing the form, I get page not found error in same URL.
I can list and create records, but can't update the records. When I run my project and click the Edit button on listed records, form page appears, but if I click Submit after completing the form, I get page not found error in same URL.
CustomerAddressModel
...ANSWER
Answered 2021-Aug-13 at 13:58Since you are using [ValidateAntiForgeryToken] at your action try to add @Html.AntiForgeryToken()
QUESTION
I created a .Net Core 5 API having 2 types of models:
- Entities (used by Entity Framework Core)
- DTOs (Data Transfer Objects for requests and responses, replacing "{Property}Id" properties from Entity with "{Property}Code" in DTO)
I have a service responsible of mapping Entities types to Dtos types added as singleton in ConfigureServices:
services.AddSingleton(typeof(IEntityDtoMappingProvider), typeof(EntityDtoMappingProvider));
The service EntityDtoMappingProvider has a method which returns the mapping between Entities and Dtos for an assembly through reflection described by this interface:
...ANSWER
Answered 2022-Jan-11 at 13:55You can register a service factory which accepts the service provider instance and uses that to resolve other services. For example:
QUESTION
I am making an app which has two separate domains, which contain models which represent different concepts:
Now, I want to create generic repository which would allow me to make operations on data sets, and I want it to be used by both DataAccess projects, because DRY. The problem is, I would write these repositories in a way that they would use id of entity, so I need base type or at least interface which will allow me for operating on those. I would create generic repository using BaseEntity
which contains ID like that:
ANSWER
Answered 2021-Oct-11 at 03:26It is hard for us to find the optimal solution without knowing the details of your project.
But I will try to give you some options:
- Extend your core library with BaseEntity definition. Benefit: That seems to follow your basic design according to the little diagram but also means your repo module will depend on the core library.
- Introduce new intermediate Layer that defines BaseEntity. If for some reason it doesn't belong into the existing Core library you can create a new library that is common to both domains and derived from Core, with the same dependency problem just on the intermediate library.
- You don't create BaseEntity and instead the Repo Module provides the necessary interfaces in pure function form, e.g. IRepoObject { getId(); } and your domain objects implement that interface. This has clean separation of concerns. (And it is not a problem that the domain module requires the repo module because they provide repo functionality now)
- Functional Programming Approach: If the data structures that the repo module needs are not overly complex you just pass those as primitives on the function calls, e.g. doRepoStuff(String id, Byte[] blob, ...). So the repo module would be agnostic to any specific classes or interface implementation.
In my experience simple solutions are usually preferable over complicated object oriented designs with deep inheritance and lots of references, so I would tend to use solution 3 or 4 depending on the complexity of data exchanged.
QUESTION
I implemented an api and I used EF core.
I have a complex structure that its core entity is an entity that I called it Project. i should say that i used EF Core as DB First. Then I created my database at first and after that I used "Scaffold-Database" to create my Model in code.
The Project's model is:
...ANSWER
Answered 2021-Oct-06 at 11:12I note you have .UseLazyLoadingProxies()
which means you can load some data from a DB and then trigger loading some more data just by accessing the property; for example you download just the one Project but as soon as you try and access its Boreholes collection, that access will trigger another query like SELECT * FROM Boreholes WHERE projectId = (whatever the current project id is)
to fill the boreholes collection before returning it..
This means when the serializer is enumerating your starting Project
's properties, looking for data it can serialize instead of getting a "null" or "empty" when it accesses the navigation proeprty to some related data, it's the serializer that is triggering a db lookup of every related entity... and then it serializes all those related entities and enumerating their props triggers even more lookups.
What starts out as just one Project, snowballs into loading every related entity up and down the tree, maybe even the whole database, just because you've asked the serializer to turn the Project object into json..
Removing the lazy loading proxies feature will stop that, but then other parts of the project won't auto load data upon access; what you do about this is perhaps a wider design decision over how you should load related data..
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install GenericRepository
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page