entity-framework-core

Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions'

本秂侑毒 提交于 2021-01-29 08:00:27
问题 Since I updated to Visual Studio 2015 update 3 and restored my Nuget packages I'm getting an Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. error.In my project.json file I have the following Entity Framework packages defined "EntityFramework.Core": "7.0.0-rc1-final", "EntityFramework.Relational": "7.0.0-rc1-final",

How to unit test a function in .NET Core 3.1 that uses ExecuteSqlRawAsync to call a stored procedure?

南笙酒味 提交于 2021-01-29 06:02:11
问题 I'm writing an API in ASP.NET Core 3.1, using EF Core to access a SQL Server database. I have a function in the API that needs to call a stored procedure with several input parameters and an output parameter. A simplified version of this function is below. I am using a DbContext with .UseInMemoryDatabase() for other tests, but the in memory database cannot be used with stored procedures. (This solution is database first, not code first. It would be possible to change the stored procedure if

Create Dbcontext at run-time

冷暖自知 提交于 2021-01-29 05:13:24
问题 I have a requirement to switch to a different data sources at runtime. sometimes user wants to connect to a different database server to manipulate data. There can be more than 100 client servers with an identical database. Original project is a .net core Web API and the server name is an input parameter. This is what I thought. Is there a better alternative? public class Person { public int Id { get; set; } public string Name { get; set; } } public class MyDbContext : DbContext { public

There is no implicit reference conversion from ApplicationUser to IdentityUser

那年仲夏 提交于 2021-01-29 04:19:18
问题 I am trying to customize some ASP.NET Identity Core classes which use Generics. My ApplicationUser class: public class ApplicationUser : IdentityUser<Guid>//, ApplicationUserClaim, ApplicationRole, ApplicationUserLogin> { public ApplicationUser() { } } My ApplicationUserStore class: public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, Guid> { public ApplicationUserStore(ApplicationDbContext ctx, IdentityErrorDescriber describer = null) : base

Write to DB after Controller has been disposed

瘦欲@ 提交于 2021-01-29 02:58:52
问题 Situation We have a controller where users can submit any number of E-Mail addresses to invite other (potential) members as friends. If an address is not found in the database, we send an E-Mail message to that user. Since the user does not has to wait for this process to complete in order to continue working this is done asynchronously. Sending E-Mails can take a long time if servers respond slowly, are down or overloaded. The E-Mail sender should update the database according to the status

EF Core one-way self referencing entity binding

匆匆过客 提交于 2021-01-29 02:28:22
问题 I have set up a self referential entity using EF Core which looks like this: Entity public class DetailType { public int DetailTypeId { get; set; } public string Name { get; set; } public int? ParentTypeId { get; set; } public DetailType ParentType { get; set; } public IEnumerable<DetailType> ChildTypes { get; set; } } Binding modelBuilder.Entity<DetailType>() .ToTable("detailtype") .HasOne(x => x.ParentType) .WithMany(x => x.ChildTypes) .HasForeignKey(x => x.ParentTypeId); I am retrieving

The SqlParameterCollection only accepts non-null Parameter type objects

对着背影说爱祢 提交于 2021-01-28 21:36:10
问题 I am trying to use stored procedures in Entity Framework Core. When executing a stored procedure, I am passing two input parameters and one output parameter. I keep getting this error: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects. This is my code: public string InsertCardsData(DateTime RecordingStartDate, DateTime RecordingEndDate) { try { // DateTime DRecEndDate = Convert.ToDateTime(RecordingEndDate); DateTime DRecEndDate =

Add middlewares on all mutations using Hot Chocolate v11

孤者浪人 提交于 2021-01-28 21:28:33
问题 I'm working on Transaction per mutation with EF core. I tried an implementation by adding my transaction logic into the Request pipeline UseRequest and it's quite good. But the problem with this implementation is that the transaction logic will be executed each time we have an incoming request Query or Mutation. I think that the Hot Chocolate middlewares can do the work by adding a middleware on all incoming mutations, but the only doc I found is about adding middlewares to fields https:/

EfCore 3.1.3 throwing Execption for OrderBy

六眼飞鱼酱① 提交于 2021-01-28 21:07:28
问题 I am trying to Order by a query using the following efcore query Getting the PropertyInfo for the column which needs to be orderedBy using this below var propertyInfo = typeof(TableVM).GetProperty("Type"); The EfCore Query db.Table **//LinkKit Extension Method** .AsExpandable() .Where(whereClause) .Select(m => new TableVM { id= m.Id, name = m.Name, description = m.Description, type = m.Type, status = m.Status }) **// Conversion of the OrderBy fails, which throws an exception saying it can't

EfCore 3.1.3 throwing Execption for OrderBy

假装没事ソ 提交于 2021-01-28 20:35:50
问题 I am trying to Order by a query using the following efcore query Getting the PropertyInfo for the column which needs to be orderedBy using this below var propertyInfo = typeof(TableVM).GetProperty("Type"); The EfCore Query db.Table **//LinkKit Extension Method** .AsExpandable() .Where(whereClause) .Select(m => new TableVM { id= m.Id, name = m.Name, description = m.Description, type = m.Type, status = m.Status }) **// Conversion of the OrderBy fails, which throws an exception saying it can't