ef-core-2.1

Remove certain properties from object upon query EF Core 2.1

旧时模样 提交于 2019-12-13 03:39:52
问题 I'm trying to null or remove the ID entirely of all the queried IsoDataTables before returning them to frontend. The idea is that it should behave (in this case) as a template and I don't want it returning the id's back to me, nor do I want them to be removed in the frontend. var applicationType = await _context.ApplicationType .Include(m => m.IsoTableData) .AsNoTracking() .FirstOrDefaultAsync(m => m.Id == id); if (applicationType == null) { return NotFound(); } if (applicationType

How to sort inheritance columns ordering in EF Core 2.1?

岁酱吖の 提交于 2019-12-12 16:38:34
问题 I used EF Core 2.1 to create SQL Server database, but database columns ordering doesn't put inheritance columns in the last, the following is my entities code: public class Blog { public int BlogId { get; set; } public string Url { get; set; } } public class RssBlog : Blog { public string RssUrl { get; set; } } Current columns ordering are: 1.RssUrl 2.BlodId 3.Url I want it in database like this: 1.BlodId 2.Url 3.RssUrl Could you tell me how to fix the database columns ordering? Thanks! I'm

How to define foreign key relationship in EF Core 2.1

馋奶兔 提交于 2019-12-12 14:07:47
问题 I am using EF Core 2.1 for my DAL. This is how my model looks like One user can have only one role: // Role entity - kind of master public class Role { public int RoleId { get; set; } public string RoleName { get; set; } } // User entity - every user will have one role public class User { public int UserId { get; set; } public string Email { get; set; } public string Password { get; set; } public int RoleId { get; set; } public bool IsActive { get; set; } public DateTime CreatedOn { get; set;

EF Core tools System.Configuration.ConfigurationManager assembly not found

天大地大妈咪最大 提交于 2019-12-11 15:58:09
问题 I am creating a new application that is using EF Core 2 with migrations. The application itself is .net Framework but the model is in a separate .net core 2.0 assembly. Everything is working fine I have defined a designtime context factory: public class MyDesignTimeContextFactory : IDesignTimeDbContextFactory<MyContext> { public MyContext CreateDbContext(string[] args) { return new MyContext("Server=localhost\\SQLEXPRESS;Database=DBName;User ID=Test;Password=0000;"); } } And I can generate

.NET Core EF Core 2 Models in 1 View Create Operation

北慕城南 提交于 2019-12-11 07:52:49
问题 Hi I have read alot but couldn't really figure out how this is suppose to work out. Following this tutorial, I couldn't quite figure out how to input data into 2 models at once with a Foreign Key mapping done properly. Supposedly I have to 2 models (following the tutorial), for example student and enrollment and I want to input data to both tables at the same time, looking at other stack overflow posts, I found out that are 2 ways to incorporate 2 views into the model, either by creating a

EF Core 2.1 Props inside where cause null reference

删除回忆录丶 提交于 2019-12-11 07:33:16
问题 When I migrated from EF 1.1 to 2.1 I started getting null reference error when iterating inside where condition, it seems like StatusCashAdvanceList is not loaded at the time where is executed. CashAdvance.cs: public virtual ICollection<StatusCashAdvance> StatusCashAdvanceList { get; set; } Stack Trace: NullReferenceException: Object reference not set to an instance of an object. lambda_method(Closure , CashAdvance) System.Linq.Enumerable+WhereSelectEnumerableIterator<TSource, TResult>

.net core 2.1 EF Core reverse engineering errors VS 2017

可紊 提交于 2019-12-11 04:10:32
问题 Not having a great time with doing EF Core Reverse Engineering. Latest error The method or operation is not implemented. Scaffold-DbContext "The method or operation is not implemented" i get the same errors for both of these commands Running this from Package Manager Console within VS 2017: Scaffold-DbContext 'Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Chinook' Microsoft.EntityFrameworkCore.SqlServer and from command prompt: dotnet ef dbcontext scaffold "Data Source=(localdb)

EF Core lock the database during migration

偶尔善良 提交于 2019-12-10 20:57:49
问题 Is it possible lock the database from any other connections when running the migrations through Database.Migrate() ? We have multiple service instances running the same code (on AWS Lambda), and do the migrations on startup. Now we have to manually make sure that only one instance is running when we want to apply some migrations, otherwise they can both try to do it and break things bad. Is there a database level solution to this? ef-core 2.1 回答1: Not really sure if this is what you are

warning EF1000. What the best way to write parameters in “IN” statement?

二次信任 提交于 2019-12-10 18:59:33
问题 EF Core 2.1 throws warnings about SQL injection. There is my code snippet where it happens var query = await _ctx.Set<TABLE>() .FromSql("Select * from TABLE where Artikelnummer IN (" + string.Join(',', artNum) + ")") .AsNoTracking() .Select(z => new { z.Artikelnummer, z.Property }).ToArrayAsync(); where artNum (stands for Artikel Numbers) is array of int numbers, like [1,22,34 etc.]. I can't pass artNum as parameters in FromSql, because there will be single quotes and SQL throws an exception.

Entity Framework Core Configuration one to zero or one relationship with same primary key

眉间皱痕 提交于 2019-12-10 11:34:16
问题 In my .NET MVC project, I have my domain classes with one to one or zero relationship as: public class Person { public int Id { get; set; } public string FullName { get; set; } public Address Address { get; set; } } public class Address { public string Address { get; set; } public string City { get; set; } public virtual Person Person { get; set; } [Key, ForeignKey("Person")] public int PID { get; set; } } This is using EF 6.x and the Address entity uses PID (which is foreign key) as its