entity-framework-core

Remove Auto Increment in EF Core 1.0 RC2 (former EF 7 RC2)

主宰稳场 提交于 2019-12-19 09:08:59
问题 In Entity Framework Core 1.0 RC2 (former Entity Framework 7 RC2), by default, all integer primary key are auto increment field. I tried everything to remove it. From using data annotation to fluent API, nothing works. Using data annotation: [Key, Column(Order = 1, TypeName = "INT"), DatabaseGenerated(DatabaseGeneratedOption.None)] Using fluent API: modelBuilder.Entity<tblProduct>().HasKey(t => t.ProdId).HasAnnotation("DatabaseGenerated", DatabaseGeneratedOption.None); //OR use the following

ObjectStateManager.ObjectStateManagerChanged in Entity Framework Core

天涯浪子 提交于 2019-12-19 09:01:43
问题 I can't seem to find ObjectStateManager.ObjectStateManagerChanged in ef core. Has this been removed and if so what is the alternative? I want to be notified whenever an entity is loaded into the context. 回答1: Currently (the latest official EF Core v1.1.2) there is no public alternative. There are plans to expose Lifetime Hooks, but according to EF Core Roadmap they are postponed and will not be available in the upcoming v2.0 release. Luckily EF Core exposes all the internal infrastructure

Automapper ProjectTo adds ToList into child properties

心已入冬 提交于 2019-12-19 08:43:23
问题 I use projection to map the Entity classes to DTOs using Entity Framework Core. However, projection adds ToList into child collection properties and this slows down the query a lot. Company Entity: public class Company { public Company() { Employees = new List<CompanyEmployee>(); } public string Address { get; set; } public virtual ICollection<CompanyEmployee> Employees { get; set; } ... } Company DTO: public class CompanyDTO { public CompanyDTO() { CompanyEmployees = new List<EmployeeDTO>();

Trying to install EF Core with Portable Class Library targeting .Net 4.6.1

Deadly 提交于 2019-12-19 08:10:24
问题 This is my first time experimenting with EF Core, ASP Net Core and Portable Class Libraries with VS2015. Fair to say I am getting frustrated. I want to create a library where I can install EntityFramework.Core. This library needs to be used in a WPF Application and an ASP NET Core Web Application - ignoring any good layered application concepts for now. My thought was to create a Portable Class Library. Using the project template where I target .NET 4.6 and ASP Net Core... I get a project

Where should I put Database.EnsureCreated?

我只是一个虾纸丫 提交于 2019-12-19 06:02:34
问题 I have an Entity Framework Core + ASP.NET Core application and when my application starts up I want to ensure that the database is created, and eventually (once I have migrations) I want to ensure that those are also run. Initially I put Database.EnsureCreated() into the constructor of my DbContext but that appears to run every time someone hits my application since a new instance of the DbContext is created each time. I tried to put it into my startup code, but I need an instance of my

Getting metadata in EF Core: table and column mappings

丶灬走出姿态 提交于 2019-12-19 05:22:03
问题 Looking to get metadata in EF Core, to work with the mappings of objects & properties to database tables & columns. These mappings are defined in the DBContext.cs OnModelCreating() method, mapping tables with .ToTable(), and columns via .Property.HasColumnName(). But I don't see this metadata under the Entity Types returned by... IEnumerable<IEntityType> entityTypes = [dbContext].Model.GetEntityTypes(); Is this metadata available anywhere in EF Core? 回答1: Is this metadata available anywhere

Persistance datalayer in EF core ,dynamic EF. Separate EF from models

泪湿孤枕 提交于 2019-12-19 04:57:45
问题 I want to separate EF layer from my model . I need a EF Builder to send my model to it like this(I found this code for mongodb but i need for EF core) : builder.AddMongo(); builder.AddMongoRepository<Cart>("Carts"); builder.AddMongoRepository<Customer>("Customers"); builder.AddMongoRepository<Product>("Products"); The above code is inside startup file . I pass the parameters from applicationsetting.json file as you can see : "mongo": { "connectionString": "mongodb://localhost:27017",

EF 7 Migrations with multiple DBContexts

对着背影说爱祢 提交于 2019-12-19 04:11:36
问题 I have a problem scaffolding and doing migrations from a class library with multiple DBContexts. I found a command line argument that looks like this for migrations: dnx ef migration add -c Contexts.IndustryContext initial But this doesn't even get by the command line parser. I want all my DBContexts and database stuff out of the main MVC 6 web project and in their own DLLs. Is this possible? What command line magic is required? 回答1: I was looking for an answer to this question and wanted to

EFCore returning too many columns for a simple LEFT OUTER join

久未见 提交于 2019-12-18 21:26:15
问题 I am currently using EFCore 1.1 (preview release) with SQL Server. I am doing what I thought was a simple OUTER JOIN between an Order and OrderItem table. var orders = from order in ctx.Order join orderItem in ctx.OrderItem on order.OrderId equals orderItem.OrderId into tmp from oi in tmp.DefaultIfEmpty() select new { order.OrderDt, Sku = (oi == null) ? null : oi.Sku, Qty = (oi == null) ? (int?) null : oi.Qty }; The actual data returned is correct (I know earlier versions had issues with

UseSqlServer method missing MVC 6

对着背影说爱祢 提交于 2019-12-18 18:36:35
问题 I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do services.AddEntityFramework() .AddSqlServer() .AddDbContext<MusicStoreContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); But for me, the UseSqlServer method isnt visible? Anyone know how to make it visible? Or is this an old way of configuring entity framework? My startup.cs file looks like this using FluentValidation; using Microsoft.AspNet.Builder;