entity-framework-core

.NET Core 1.0 and EntityFramework 7 Not Compatible

人盡茶涼 提交于 2019-12-12 15:41:31
问题 I've upgraded to Visual Studio Code 1.0.0 and I'm trying to retrofit an ASP.NET Core project I was working on in VSCode previously, before the new release. VSCode is seemingly quite different now in terms of configuration. I've worked with this tutorial and these samples. I'm having reasonable success getting the MVC6 aspect of my project compiling and working properly, but the EntityFramework 7 aspect is a no-go. When I do a dotnet restore on my project, I get the following error: Package

EF Core DbUpdateConcurrencyException does not work as expected

纵饮孤独 提交于 2019-12-12 15:35:39
问题 I have the following code that I am trying to update ClientAccount using ef core but they Concurrency Check fails: public class ClientAccount { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long Id { get; set; } [Required] [ConcurrencyCheck] public double Balance { get; set; } [Required] public DateTime DateTimeCreated { get; set; } [Required] public DateTime DateTimeUpdated { get; set; } } public class ClientRepository { private readonly MyContext context; public

How to trace an Entity Framework Core event for integration testing?

橙三吉。 提交于 2019-12-12 14:45:55
问题 We need to ensure that EF Core-based code has performed a specific kind of database-level operation under test (for example, any command execution or any transaction commit). Let's suppose a real database should be triggered and we can't isolate it by DbContext mocking. How could it look: [Fact] public async Task Test() { using (var context = new FooContext()) { //context-related code to produce queries and commands } Assert.True(/* any context-related transaction has been committed */); } Is

EFCore - How to have multiple navigation properties to the same type?

三世轮回 提交于 2019-12-12 13:35:24
问题 My model contains the classes Post and PostHistory, where Post has a one-to-many relationship with PostHistory. class Post { public int Id { get; set; } public PostVersion CurrentVersion { get; set; } public PostVersion OriginalVersion { get; set; } public IList<PostVersion> History { get; set; } } class PostVersion { public int Id { get; set; } public Post Post { get; set; } public string Title { get; set; } public string Body { get; set; } } The History property contains a list of all

MissingMethodException DbSet.ToList

不问归期 提交于 2019-12-12 13:27:16
问题 On my Entity Framework Core project I've a generic repository with a GetAll() method public ICollection<Entity> GetAll(){ return DbSet.ToList(); } But when I execute it, throws the following: System.MissingMethodException was unhandled HResult=-2146233069 Message=Method not found: 'Void Microsoft.EntityFrameworkCore.Query.QueryContextFactory..ctor(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager, Microsoft.EntityFrameworkCore.Internal.IConcurrencyDetector, Microsoft

Predicate build with NET Core and EF Core

时间秒杀一切 提交于 2019-12-12 12:47:44
问题 Very quick question : I'm trying to create a predicate builder like this : var predicate = PredicateBuilder.False<MyObject>(); But seems that is not available in Net Core And EF Core . Am I missing a package or something ? 回答1: Are you sure that the PredicateBuilder you were using was not a custom class? A PredicateBuilder is shipped as part of LINQKit but the source is also available here as follows: public static class PredicateBuilder { public static Expression<Func<T, bool>> True<T>() {

Method not found: 'Void EntityFrameworkCore.Design.Internal.DbContextOperations

我们两清 提交于 2019-12-12 12:45:27
问题 I am trying to scaffold and getting following error: There was an error running the selected code generator Method not found: 'Void EntityFrameworkCore.Design.Internal.DbContextOperations 回答1: https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db?view=aspnetcore-2.0#install-entity-framework I suspect you are missing the assemblies that are necessary for scaffolding? I also assume you are trying to reverse engineer an existing db? example Scaffold-DbContext "Server=

ASP.NET and EF Core - ModelState.IsValid always returns true for models generated by Scaffold-DbContext

偶尔善良 提交于 2019-12-12 12:25:01
问题 I've been unable to validate models generated by the Scaffold-DbContext command in my ASP.NET Core controllers. The required/max length property configurations are all in the onModelCreating method of the context class that EF core generated. protected override void OnModelCreating( ModelBuilder modelBuilder ) { modelBuilder.Entity<ModelClass>( entity => { entity.ToTable( "ModelClass", "schema" ); entity.Property( e => e.ModelClassCode ) .IsRequired() .HasMaxLength( 30 ); My controller

EF Core Include() in Many to Many relation

纵饮孤独 提交于 2019-12-12 12:19:29
问题 The relation between Product and Customer is of type many-to-many (from a design point a view). Using EF Core, we split this relation in two one-to-many relations with a third entity: ProductCustomer public partial class ProductCustomer { public long ProductId { get; set; } public long CustomerId { get; set; } public virtual Customer Customer { get; set; } public virtual Product Product { get; set; } public virtual ICollection<UsageRecord> UsageRecord { get; set; } } UsageRecord is a list of

How do I implement a simple “complex type” in Entity Framework Core 2/C#?

ぐ巨炮叔叔 提交于 2019-12-12 12:16:25
问题 I'm using Entity Framework and .Net Core 2.0 for the first time (I'm also pretty new to C#, but I've been using the traditional .Net Framework & VB since version 1... so I'm no newbie to .Net development), and I've already run into a problem creating my database. Take this simple scenario: I want to store some information about some electric pumps. Two of the properties are a min/max type range, so I've implemented these as a simple class, thus: public class Pump { [Key] public int pumpId {