entity-framework

Table per Type in Entity Framework Core 2.0

限于喜欢 提交于 2020-01-23 03:08:18
问题 These are my models: public class Company { public int CompanyId { get; set; } public string Name { get; set; } public string Address { get; set; } public string Email { get; set; } public string Url { get; set; } //... } public class HeadOffice : Company { public int HeadOfficeId { get; set; } public virtual List<BranchOffice> BranchOffice { get; set; } = new List<BranchOffice>(); } public class BranchOffice : Company { public int BranchOfficeId { get; set; } public virtual HeadOffice

Table per Type in Entity Framework Core 2.0

筅森魡賤 提交于 2020-01-23 03:08:03
问题 These are my models: public class Company { public int CompanyId { get; set; } public string Name { get; set; } public string Address { get; set; } public string Email { get; set; } public string Url { get; set; } //... } public class HeadOffice : Company { public int HeadOfficeId { get; set; } public virtual List<BranchOffice> BranchOffice { get; set; } = new List<BranchOffice>(); } public class BranchOffice : Company { public int BranchOfficeId { get; set; } public virtual HeadOffice

DbContext Slow Loading

自作多情 提交于 2020-01-23 03:07:10
问题 I have WPF applicaton, and in every usercontrol.xaml.cs file I have a field private readonly DBContextManager dbManager = new DBContextManager(); Class DBContextManager: public class DBContextManager : DbContext { public DBContextManager() : base("App_DbContext") { Database.SetInitializer<DBContextManager>(null); } public DbSet<Person> Persons { get; set; } } So, first time when I open usercontrol state which uses DbContext, it takes 2-4s to load before that usercontrol interface will show up

Get all users with a specific role in ASP.NET Core 2.0

六眼飞鱼酱① 提交于 2020-01-22 21:22:04
问题 I'm just getting started with porting a application from ASP.NET MVC 5 to ASP.NET Core 2.0 (with EF Core and Identity). All has been going smooth, but I've ran into a problem that I can't seem to find an answer to. What I want to do is simply to fetch all users in a database, based on the role they are assigned (Admin, User, etc.). This was simple in MVC 5 where I was just using: _db.UserCompany.Where(x => x.User.Roles.Any(s => s.RoleId == adminRole.Id) However, with .NET Core / Entity

migrate.exe ignoring binding redirects

浪尽此生 提交于 2020-01-22 20:06:09
问题 I am trying to run the migrate.exe application from EntityFramework on a specific DLL. This DLL references the Microsoft.Azure.KeyVault.WebKey nuget package. When I try to run the command ./migrate MyProject.Data /startUpDirectory=C:\myDir /startUpConfigurationFile=C:\myDir\Redirect.config I get the following error ERROR: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6ae ed' or one of its dependencies. The located assembly's

Entity Framework “Invalid attempt to read when no data is present” with 'large' data on Azure

可紊 提交于 2020-01-22 19:47:05
问题 I am using Entity Framework (v4.0) to connect to SQL Azure (I have the March SDK installed) and getting a InvalidOperationException when trying to query a table. The message of the exception is Invalid attempt to read when no data is present. and the stack trace clearly shows that this is failing internally in EF when it attempts to get the column header: at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i) at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i) at lambda_method

SQL Server CE Code First migrations problems

馋奶兔 提交于 2020-01-22 19:44:37
问题 I have a bunch of problems trying to enable (code-first) migrations for my SQL Server Compact 4.0 database for my desktop .NET app. Enable-Migrations does work and the directory Migrations is created. After that when I try to run Add-Migration InitialMigration , I get: Access to the database file is not allowed. [ 1914,File name = Logo.sdf,SeCreateFile ] This is the first problem, but I solved it by running Visual Studio as Administrator... don't like that solution and also don't know if

SQL Server CE Code First migrations problems

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-22 19:42:12
问题 I have a bunch of problems trying to enable (code-first) migrations for my SQL Server Compact 4.0 database for my desktop .NET app. Enable-Migrations does work and the directory Migrations is created. After that when I try to run Add-Migration InitialMigration , I get: Access to the database file is not allowed. [ 1914,File name = Logo.sdf,SeCreateFile ] This is the first problem, but I solved it by running Visual Studio as Administrator... don't like that solution and also don't know if

How do I map an OData query against a DTO to an EF entity?

纵然是瞬间 提交于 2020-01-22 19:02:05
问题 I have an ODataController in an Asp.Net Web Api application that allows OData queries. I'm only allowing reads, not updates. Instead of exposing the data model directly, I've created a set of DTOs. The property names on the DTOs do not necessarily match the properties on the EF model. This causes a problem when I try to use the OData query against the EF model. I've looked at other posts on StackOverflow around this subject but none of them seemed to resolve this issue. Here is what I have

Unit testing a two way EF relationship

杀马特。学长 韩版系。学妹 提交于 2020-01-22 18:42:46
问题 I'm doing a small practice project to improve my unit testing skills. I'm using Entity Framework Code First. I'm using a FakeDBSet, which works well for simple lists of entities. When entity trees are returned things aren't so nice. In particular two way relationships aren't maintained as this is part of the Entity Framework magic. I have two classes: public class Book { public virtual ICollection<Review> Reviews {get; set;} } public class Review { public virtual Book Book { get; set;} } If I