entity-framework-core

Add-Migration Value cannot be null. Parameter name: language

社会主义新天地 提交于 2019-12-08 20:21:23
问题 I am trying to create a new migration but I get an System.ArgumentNullException saying: System.ArgumentNullException: Value cannot be null. Parameter name: language at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor (IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String projectDir, String rootNamespace, String language) at Microsoft.EntityFrameworkCore

EFCore Map 2 entities to same table

倖福魔咒の 提交于 2019-12-08 19:11:06
问题 I'm trying to use DDD with EFCore and I am struggling to find a way to map 2 POCOs from different context that represent the same entity to the same table. I have a User class inside UserContext, with all the properties needed to create a new user to my application. And I have either a User class inside my OrderContext, in this class I only have the Id and Email properties, cause it's all that is needed in OrderContext to work. So I have something like this: modelBuilder.Entity<Domain

EF Core 'another instance is already being tracked'

会有一股神秘感。 提交于 2019-12-08 18:23:56
问题 I have a problem updating an entity in .Net Core 2.2.0 using EF Core 2.2.3. An error occurred while saving changes. Error details: The instance of entity type 'Asset' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using This is how the DB Context is registered: services.AddDbContext(options => options.UseSqlServer

Issues with SQL Alias in ConnectionString in appsettings.json

余生颓废 提交于 2019-12-08 17:24:57
问题 In my appsettings.json, when I use this snippet: "ConnectionStrings": { "CssDatabase": "Server=BLUEJAY\\MSSQLSERVER2014;Database=CSS;Trusted_Connection=True;" } I can connect to the db as expected... no issues. However, when I change that to use the SQL Alias (CSSDB), like so: "ConnectionStrings": { "CssDatabase": "Server=CSSDB;Database=CSS;Trusted_Connection=True;" } It is properly configured since I can use this SQL Alias in SSMS to connect to DB without an issue. This returns: The server

add-migration : Cannot bind argument to parameter 'Path' because it is an empty string

时光总嘲笑我的痴心妄想 提交于 2019-12-08 16:27:38
问题 I'm running default api core project on Visual studio 2017 with docker support and I got this error everytime I run the command add-migration -name name add-migration : Cannot bind argument to parameter 'Path' because it is an empty string. At line:1 char:1 + add-migration + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-Migration], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Add-Migration PS : This command works

Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design - dotnet.exe crashes

杀马特。学长 韩版系。学妹 提交于 2019-12-08 16:24:53
问题 Please look below for the data given in Package Manager Console. I can't do a Add-Migration. When I do the dotnet.exe crashes. PM> Add-Migration 1 Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. PM> dotnet --info .NET Command Line Tools (1.0.0-preview2-003131) Product Information: Version: 1.0.0-preview2-003131 Commit SHA-1 hash: 635cf40e58 Runtime

Get DbSet from type

北城余情 提交于 2019-12-08 15:07:18
问题 I am attempting to make a generic table viewer/editor for an MVC 6 application. I currently use Context.GetEntityTypes(); To return me a list of tables. Now I need to fetch the data for a specific type. My current implementation is: // On my context public IQueryable<dynamic> GetDbSetByType(string fullname) { Type targetType = Type.GetType(fullname); var model = GetType() .GetRuntimeProperties() .Where(o => o.PropertyType.IsGenericType && o.PropertyType.GetGenericTypeDefinition() == typeof

Intermittent error with EF Core: The connection does not support MultipleActiveResultSets

家住魔仙堡 提交于 2019-12-08 14:45:13
问题 I have an ASP.Net Core application that uses EF Core. I use ASP.Net Identity and share the same DBContext for my app's entities. I have set my connection string to an Azure SQL database to have MultipleActiveResultSet=True. It works for a day or two, but eventually it fails with the error: The connection does not support MultipleActiveResultSets. I don't think MARS is the real issue since it worked for the first two days it was up. I am using ASP.Net Core's built-in DI to set my DbContext.

EF Core nested Linq select results in N + 1 SQL queries

∥☆過路亽.° 提交于 2019-12-08 14:42:18
问题 I have a data model where a 'Top' object has between 0 and N 'Sub' objects. In SQL this is achieved with a foreign key dbo.Sub.TopId . var query = context.Top //.Include(t => t.Sub) Doesn't seem to do anything .Select(t => new { prop1 = t.C1, prop2 = t.Sub.Select(s => new { prop21 = s.C3 //C3 is a column in the table 'Sub' }) //.ToArray() results in N + 1 queries }); var res = query.ToArray(); In Entity Framework 6 (with lazy-loading off) this Linq query would be converted to a single SQL

Cannot override OnConfiguring in beta5 - no suitable method found to override

本小妞迷上赌 提交于 2019-12-08 13:44:30
问题 After updating EF7 to beta5 from beta4 my OnConfiguring stopped working. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) I can't figure out what I need to write instead. Here's my project.json , just in case { "dependencies": { "EntityFramework.SqlServer": "7.0.0-beta5", "EntityFramework.Commands": "7.0.0-beta5", ... } } it doesn't have "EntityFramework": "7.0.0-beta4" (no beta5 yet). It apparently isn't needed. DNVM list Active Version Runtime Architecture