entity-framework-core

DbContext not updating database

末鹿安然 提交于 2019-12-24 19:08:19
问题 When I save changes to DbContext, it doesn't update my database. No errors either. Yes, the incoming form data is filled. Yes, the connection string is correct, I know this because I'm able to retrieve data from the database perfectly fine. If it's of relevance, it's a many-to-many relationship. A roadmap is like an article as far as you're concerned which can be associated with many tags. public static class RoadmapService { static ConkerDbEntities dbContext; public static void

How can I implement “Soft Deletes” with “Entity Framework Core” (aka EF7)?

情到浓时终转凉″ 提交于 2019-12-24 18:29:03
问题 I'm trying to implement a "Soft Delete" using EF7. My Item table has a field named IsDeleted of type bit . All of the examples that I see around SO and elsewhere are using something like this: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Item>().Map(m => m.Requires("IsDeleted").HasValue(false)); } but Map() is no longer a method of ModelBuilder . EDIT: Let me clarify. I'm mostly only interested in reading the data right now. I want EF to

Multi-targeting .net core 2.2 with .net 4.6.1

懵懂的女人 提交于 2019-12-24 17:28:48
问题 I had started on an application on gathering data from meteorological stations for some time now and to make it cross platform I used .net core 2.2 mvc along with some libraries. Even though the data is saved in a mysql db, the client recently requested that selected meteo records from a list, to be saved in a local access db. To achieve that I had to use the legit database provider from microsoft which in this case is EntityFrameworkCore.Jet . I didn't know that there was a compatibility

MapTo() inside of LINQ returning multiple iterations of same data

蓝咒 提交于 2019-12-24 17:24:49
问题 I am using .NET Core with the ASP.NET Boilerplate framework. In some code that I was given to fix, we had a GetAll() method that was supposed to return a collection of rows from the MsSql database. The original code: public IEnumerable<GuidelineCategoriesDto> GetAll(bool activeFilter = true) { return _guidelineCategoriesRepo.GetAll().Select(x => x.MapTo(new GuidelineCategoriesDto())).ToList(); } The problem I was running into with this method, is that it would return the latest row that had

using Max() in Orderby

天涯浪子 提交于 2019-12-24 16:45:59
问题 I have this line which runs till I enabled RelationalEventId.QueryClientEvaluationWarning. Here let's say what I want to do is to sort the results (customers) based on their latest order date. .OrderByDescending(x=>x.orders.Max(y=>y.CreateDate)) After I configure the context as follow I realised the Max() is not converted to TSql. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); optionsBuilder.ConfigureWarnings(warning => {

Entity Framework 7 Invalid Column Name

亡梦爱人 提交于 2019-12-24 15:59:19
问题 I'm creating EF7 mappings for an existing database and I'm getting an "Invalid column name" error. The code that is throwing the error is: public class DepositContext : DbContext { public DbSet<tblBatch> Batches { get; set; } public DbSet<tblTransaction> Transactions { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<tblBatch>().HasKey(b => b.BatchID); modelBuilder.Entity<tblTransaction>().HasKey(t => t.TransactionID); modelBuilder.Entity

Selecting all rows based on a distinct column in Entity Framework Core

坚强是说给别人听的谎言 提交于 2019-12-24 15:27:42
问题 I have a table with some data which I want to select rows with unique dates using the .NET core entity framework. I want to return the results as a list of the unique rows. Here is the code. public async Task<IEnumerable<Records>> GetUniqueRecordsByDate(int bId) { var rowsToReturn = await _context.Records .Where(b => b.SId == bId) .Select(d => d.Date) .Distinct() .OrderBy(d => d) .ToListAsync(); return rowsToReturn; } I'm trying to apply the above code but I get this error Cannot implicitly

dotnet core 2.0 pluralize when scaffolding?

梦想与她 提交于 2019-12-24 14:06:51
问题 Setting my a .net core 2.x class library with ef core 2. Have generated the scaffolding for the entities from my db schema. However, I forgot to even check whether there as an option to pluralize the entity names. I noticed this when I pulled over one my methods from a class library that uses EF 6.1 and the entities are pluralized. Is there an option for this and to simply regenerate my entities as pluralized? 回答1: Write a class that implements the Microsoft.EntityFrameworkCore.Design

Ef core migrations in full .net project in VSTS

廉价感情. 提交于 2019-12-24 12:07:56
问题 I have created a .net core web app targeting the full .net framework I Have created a class library (.net framework) In this dll I have referenced ef core and created a context. Migrations work when I use the package manager. The Problem I am currently facing I need to be able to use migrations during a VSTS deployment. I have tried creating a powershell deployment script in VSTS to call dotnet-ef commands. This doesn't work, because I can't install Microsoft.EntityFrameworkCore.Tools.DotNet

What SQL Server 2017 features are not supported in Entity Framework Core code first?

走远了吗. 提交于 2019-12-24 11:12:39
问题 Our team is thinking of utilizing Entity Framework Core code-first to help model the database. We can have both DB projects and EF models, as per article here Database Projects vs. Entity Framework Database Migrations utilizing schema compares, just trying to figure out what will be the source of truth? Does Entity Framework support all features in SQL Server SSDT Database Projects? What features does EF Core 2 not support? (eg, does it not support any of following: triggers, views, functions