entity-framework-core

Performance of Entity Framework Core

我与影子孤独终老i 提交于 2019-12-11 05:25:54
问题 I'm quite new to the EF Core. I always used the EF 6.0 and never had to use an include. Now the question comes up how i should work with these includes. I figured out three possible options and wanted to know wich would you prefer to use/which is the fastest and why? In these samples my intention is to get the details of a club. I want to check if a club with the corresponding id exists and then get the whole information. Option 1: using (var context = new TrainingSchedulerContext()) { var

Cannot connect to SQL Server on ASP.NET Core 1 EF7

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:24:12
问题 I am trying to connect to SQL Server 2014 or 2016 from an ASP.NET Core 1.0 web application (Entity Framework Core). I am getting the error below. Any tips how to resolve it. I can successfully connect to the DB from through Visual Studio 2015 SQL Server Object Explorer. However the connection from the web application fails. Neither I can do dotnet ef database update . I can connect to LOCALDB. My connection string looks like: "DefaultConnection": "Data Source=server;Initial Catalog=TestDb

How to combine both of code first and database first approaches

 ̄綄美尐妖づ 提交于 2019-12-11 05:22:14
问题 Let's say I'm a new developer in a company. So there is already an existing database for the project. To work on the project, obviously I need to scaffold the existing database(database first approach), which can generate model classes for me to work on. So I start to work on the project and want to add a new column to a table, so I add a new property on the model class then I want to apply this change in the database. So I switch back to code first approach by adding a new migration and

Seeding database imlementation of EF6 not working in EntityFrameworkcore

旧城冷巷雨未停 提交于 2019-12-11 05:16:21
问题 My implementation code for seeding in Entity Framework 6 dosent seem compatible with EntityFramework core Here is my code public class CustomerOrderSeedData : DropCreateDatabaseIfModelChanges<CustomerOrderEntities> { protected override void Seed(CustomerOrderEntities context) { GetOrderDetails().ForEach(od => context.OrdersDetails.Add(od)); context.Commit(); } private static List<OrdersDetails> GetOrderDetails() { return new List<OrdersDetails> { new OrdersDetails { OrderId = 1, ProductId = 1

How to not specify SQL expression in HasComputedColumnSql of EF Core Fluent API in DB first approach?

ε祈祈猫儿з 提交于 2019-12-11 05:01:22
问题 In previous version of EF, to specify a computed column we would write: modelBuilder .Entity<Type>() .Property(x => x.ComuptedProperty) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed); This would make sense, because the SQL expression for the computed column is written once in database. However, after migrating to EF Core, we realized that the syntax should be changed into: modelBuilder .Entity<Type>() .Property(x => x.ComuptedProperty) .HasComputedColumnSql("SQL Expression

Entity Framework Core Data Annotation Database Generated Values

大兔子大兔子 提交于 2019-12-11 04:58:18
问题 The Entity Framework Core documentation for Generated Properties makes it seem like Data Annotations can be used for generated code first "timestamp" properties such as created/updated on as a DateTime type. When trying to use the following data annotations along with code first migrations: public class Foo { // some properties [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public DateTime Created { get; set; } // more properties } I receive the following error when attempting to

EF Core with SQL Server persistence requires VIEW SERVER STATE permissions?

本秂侑毒 提交于 2019-12-11 04:53:22
问题 If I use EF Core against SQL Server, and the user account on the connection does not have permissions for VIEW SERVER STATE on object 'server', database 'master', the operation will fail with a DBUpdateException stating that this permission is missing. What is EF Core trying to do that requires this permission? Is there any way for me to disable whatever it is doing that requires it? or do I have to add this permission? 来源: https://stackoverflow.com/questions/46347476/ef-core-with-sql-server

foreign key of sql scripts generated by visual studio are different

人盡茶涼 提交于 2019-12-11 04:24:50
问题 I have two Entity classes : public class User { public string Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } [InverseProperty("User")] public virtual UserDetail UserDetail { get; set; } } public class UserDetail { public string Biography { get; set; } [Key] public string UserId { get; set; } [ForeignKey("UserId")] public virtual User User { get; set; } } And the DbContext is : public class AppDbContext : DbContext { public AppDbContext

can not upgrade from EF Core 1.1.2 to version 2.0.0

好久不见. 提交于 2019-12-11 04:22:50
问题 All, I recently started working on a project that uses EF Core 1.1.2. I saw where 2.0 was released because I started getting errors when I tried to add EF core to a project. I couldn't update the existing project, I created a brand new console project. Set the .Net framework to 4.6.1 and still had no luck. I always get the following message. Has anyone ran into this issue? thanks in advance Install-Package : Could not install package 'Microsoft.EntityFrameworkCore.SqlServer 2.0.0'. You are

EF core - Creating a migration for a database without a connection string and in another class library

只谈情不闲聊 提交于 2019-12-11 04:08:27
问题 I want to create a migration for a second and subsequent databases that's in a class library different from the project that uses it. There is a wrinkle. I will never know the connection string until a user logs in and I can get it from a catalog database (saas). For the catalog database I used the solution from this site. That was fine - This database has its connection string in appsettings.json and can uses dependency injection. The client databases are all going to be identical using the