entity-framework-core

What is the best way to perform partial updates in EF core and never update certain properties?

瘦欲@ 提交于 2019-12-18 16:32:25
问题 I know you can do something like var myObj = _db.MyTable.FirstOrDefault(x=>x.Id==id) and then update myObj property by property that you want to update but is there a better way to update say 6 out of 10 properties of myObj and leave the other 4 alone or have them marked as a way that they are only set once and never updateable from ef core? public class MyObject { public string Id { get; set; } public string Prop1 { get; set; } public string Prop2 { get; set; } public string Prop3 { get; set

ef-core load collection property of nested tph inherited member

混江龙づ霸主 提交于 2019-12-18 13:15:15
问题 Given the following class structure public class Parent { public Guid Id { get; public List<BaseChild> Children { get; set; } } public abstract class BaseChild { public int Id { get; set; } public string ChildName { get; set; } } public class NormalChild : BaseChild { public DateTime BirthDate { get; set; } } public class RichChild : BaseChild { public List<OffshoreAccount> OffshoreAccounts { get; set; } } public class OffshoreAccount { public string AccountNumber { get; set; } public

EntityFramework Commands in ASP.Net 5 Class Library Package?

你离开我真会死。 提交于 2019-12-18 12:26:50
问题 I am trying to develop my first ASP.Net web application and in my solution I have two projects. A Web Application and Class Library (Package) . When I build the ASP.Net 4.5 version of this application I put my Entity Framework 6 entities into a class library, so I am doing that in the ASP.Net 5 version. The problem is when I install EntityFramework.Commands to the class library I get the error: The dependency EntityFramework.Command 7.0.0-rc1-final in Project DBEntities does not support

Is EF Core Add Migration Supported from .NET Standard Library?

陌路散爱 提交于 2019-12-18 11:52:59
问题 We have been trying to run EF Core Migration in .Net Standard 1.6 class library, but it has been failing. But same passes very well in .Net Core 1.1 class library. Is EF Migration supported in .NET STANDARD? 回答1: The documentation covers this case as know issue/limitation when the DbContext is placed inside an netstandardx.y Class Library. Workaround 1 - Use an app as the startup project If you have an existing .NET Core App or .NET Framework App (including an ASP.NET Core Web Application),

How to implement the field decimal(5,2) in EntityFrameworkCore 1.0 rc2?

烂漫一生 提交于 2019-12-18 11:46:03
问题 How to implement the field decimal(5,2) in EntityFrameworkCore 1.0 rc2 ? HasPrecision seems to be not available anymore? 回答1: I'm seeing some examples like this: entityBuilder.Property(r => r.TotalScore) .HasColumnType("decimal(5,2)") .IsRequired(true); and the code to support this is here, so hopefully this is supported in the version you're using: https://github.com/aspnet/EntityFramework/blob/f416dd9a71a5a6a69715b4ba40a37e6f9da751ef/src/Microsoft.EntityFrameworkCore.Relational/Metadata

How to get user information in DbContext using Net Core

落花浮王杯 提交于 2019-12-18 11:08:00
问题 I am trying to develop a class library in which i want to implement custom DbContext . In the SaveChanges method of the DbContext , i need to get current user’s information(department, username etc.) for auditing purpose. Some part of the DbContext code is below: public override int SaveChanges() { // find all changed entities which is ICreateAuditedEntity var addedAuditedEntities = ChangeTracker.Entries<ICreateAuditedEntity>() .Where(p => p.State == EntityState.Added) .Select(p => p.Entity);

Error Could not load type System.Data.OleDb.OleDbConnection from assembly System.Data when using Scaffold-DbContext, EntityFrameworkCore.Jet, .NetCore

久未见 提交于 2019-12-18 09:21:12
问题 I am trying to use Scaffold-DbContext from Entity Framework Core to create Models from an existing MS Access Database. In Package Manager Console when I run the command: Scaffold-DbContext "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Folder\Database.mdb;" EntityFrameworkCore.Jet I get the following error: Could not load type 'System.Data.OleDb.OleDbConnection' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=123123123'. I'm using a ClassLibrary project with

System.Data.SqlClient is not supported on this platform

坚强是说给别人听的谎言 提交于 2019-12-18 07:46:17
问题 I'm using ASP.NET Core 2 with Entity Framework Core 2.0.2. I created a context and Add-Migrations command in Package Manager Controller works fine. However when Update-Database command is used, I get an error: System.Data.SqlClient is not supported on this platform I can't figure out where the problem is. Can you help me? Thanks. My .csproj file: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <DebugType>portable</DebugType>

Ef core fluent api set all column types of interface

痴心易碎 提交于 2019-12-18 07:11:50
问题 Unfortunately ef core does not support TPC-pattern, but we need this kind of behaviour. I´ve wrote an interface which is called IBase and each entity implements this interface: public interface IBase { Guid Id { get; set; } [Column(TypeName = "datetime2")] DateTime CreateDate { get; set; } [Required] [StringLength(255)] string CreateUser { get; set; } bool Deleted { get; set; } } I want to get rid of Annotations to use the Fluent API configuration instead. But I have about 20 different

The navigation on entity type has not been added to the model, or ignored, or entityType ignored

↘锁芯ラ 提交于 2019-12-18 06:08:56
问题 The navigation 'Tags' on entity type 'Notepad.Models.Note' has not been added to the model, or ignored, or entityType ignored. public class Note { public Note() { CreationDate = DateTime.Now; Tags = new HashSet<Tag>(); Parts = new HashSet<Part>(); } public int ID { get; set; } public virtual ICollection<Tag> Tags { get; set; } public virtual ICollection<Part> Parts { get; set; } public DateTime? CreationDate { get; set; } } public class Tag { public Tag() { Notes = new HashSet<Note>(); }