entity-framework-core

EF Core Migrations manual edits possible?

∥☆過路亽.° 提交于 2019-12-13 16:51:01
问题 I am using EF Core 2.0 in my sample project with some value object configurations. I modify the code and generate migrations via CLI command line. In the last migration rather than adding a new database table as it should, it is trying to rename existing tables to each other and create an extra table for existing one. I could not figure out the reason for it. Issue is, since with EF Core the snapshot is a separate auto-generated file from the migration itself I don't want to modify the

How to add db context not in ConfigureServices method ASP.NET Core

笑着哭i 提交于 2019-12-13 16:32:40
问题 Is there any posibility to add a db context in external class/method "on fly?" When I run the application, there is no any connection string, so I need to generate a db after typing some information(server, dbname, ect) 回答1: One way is to use the factory pattern, i.e. creating a service that will be used to create new instances of your context. Here is an example, it is not a final solution and you will need to adapt it to your needs but it should give you an idea of the technique: public

Ambiguous column name 'name' error when scaffolding dbcontext

南笙酒味 提交于 2019-12-13 16:07:48
问题 I'm trying to scaffold from an existing database but the database has multiple tables with multiple schemas and some tables have the same names but within different schemas and i "think" this is the source of my problem and I was wondering if you've faced a similar scenario? For example mySchema1.contacts and mySchema2.contacts in the same database. Here is my command: dotnet ef dbcontext scaffold "Data Source=database;Initial Catalog=table;Integrated Security=True;Connect Timeout=30;Encrypt

Adding new column using Update-Database in Entity Framework Core

笑着哭i 提交于 2019-12-13 15:27:38
问题 May be i'm missing something very obvious. But i haven't been able to figure out a way to add a new column to an existing table/model in EF Core. This is the documentation that I'm following: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell And this is what i have done so far: Created migration using this command: "Add-Migration -Name CodingSoldierDbContextMigration -OutputDir Migrations -Context CodingSoldierDbContext" Updated database using the command: "Update-Database

Entity Framework Core error not seen before Class.TempProperty is of type 'object' which is not supported by current database provider

荒凉一梦 提交于 2019-12-13 15:21:43
问题 I am using Entity Framework Core code-first with fluent API entity configurations, in an ASP .NET MVC Core application. My code currently compiles, but when I run add-migration in the Package Manager Console, it gives the error below: The property 'Exam.TempId' is of type 'object' which is not supported by current database provider. Either change the property CLR type or manually configure the database type for it. Searching Google for this error yields no results. Can anybody here help

Configuring abstract base class without creating table in EF Core [duplicate]

纵饮孤独 提交于 2019-12-13 15:00:19
问题 This question already has an answer here : Entity Framework Core 2.0: How to configure abstract base class once (1 answer) Closed 11 months ago . I have added DateCreated , UserCreated , DateModified and UserModified fields to each entity by creating a BaseEntity.cs class. My requirement is to generate single table which is having all the fields of base class as columns. public class BaseEntity { public DateTime? DateCreated { get; set; } public string UserCreated { get; set; } public

How handle these two models in code first approach using Entity Framework 7?

女生的网名这么多〃 提交于 2019-12-13 13:23:08
问题 Problem I am coding proof of concept ASP.NET 5 MVC6 that will simulate a library. I am using CTP6 and beta3. How to define their relationship in Entity Framework 7 using code first approach? Shelf and Books need a join table. As I see it, this application will consider one shelf at a time and the books on that self. In other words, one shelf has a one to many relationship with books. Models Shelf model: public class Shelf { public int ShelfId { get; set; } public string ShelfName { get; set;

Issue on looping over a list of ViewModel using for loop

喜你入骨 提交于 2019-12-13 09:17:56
问题 In the following controller, I need to loop through each element of a List. MyVieModel has quite a number of attrubutes (columns) and the list has thousands of rows. So, for brevity I need to use an outer and an inner loop. But, the VS2015 is complaining at the following lines in the controller. How can I resolve the issue? Error at inner loop for (var j = 0; j < testlist[i].Count(); j++){...} : MyViewModel does not contain a definition of Count() Error at line if (testlist[i][j] ....){...} :

Query does not return child collections

一世执手 提交于 2019-12-13 08:46:15
问题 I still struggle with this, why each of 'Category' items returns null 'Task' collections. I do have data in the database, what am I missing? public class ApplicationUser : IdentityUser { public ICollection<Category> Categories { get; set; } } public class Category { public int CategoryId { get; set; } public string Name { get; set; } public DateTime Timestamp { get; set; } public ICollection<Task> Tasks { get; set; } } public class Task { public int TaskId { get; set; } public string Name {

Create POCO class in EF 7 code first

喜欢而已 提交于 2019-12-13 08:25:38
问题 Say I have three tables. Settings, Facilities and FacilitySettingOverride in an existing database. The sample data: Settings table ID Name Value 1 test1 true 2 test2 true Facilities table ID Name 163 Demo1 164 Demo2 FacilitySettingOverride FacilityId SettingId Value 163 2 False 164 1 False 164 2 False FacilitySettingOverride has two foreign keys---FacilityId and SettingId. Also I want to make a composite key for FacilitySettingOverride. I just don't know how to make it. My primary code.