entity-framework-core

How to combine both of code first and database first approaches

ぃ、小莉子 提交于 2019-12-02 04:50:48
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 update the database. But the problem is, if I add a new migration, EF will include all the data model

Avoid Exposing Private Collection Properties to Entity Framework. DDD principles

安稳与你 提交于 2019-12-02 04:08:43
I try do adhere DDD principles on C# collections see more here And I notice that the model builder method for initial seed HasData relies on the Add Method of ICollection . There is any way to circumvent or trick that method when is called from database update / migrate process? All I had done until now to trick it follows this path. 1) Create a wrapper around the ICollection named ReadOnlyKollection 2) Have a private ICollection on the model, to avoid exposing to the outside world the collection. 3) Expose the wraper making obsolete Add and some other methods that will trow

DescriptionAttribute not available in DNX Core 5.0

孤街醉人 提交于 2019-12-02 04:01:33
问题 I'm having an issue with DescriptionAttribute in ASP.NET 5 project. I wanted to use DescriptionAttribute for my enum class, but the project cannot be built due to missing reference in DNX Core 5.0 Here's my project.json file { "userSecretsId": "", "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1

Can't add Entity Framework Core migrations to .NET Standard 2.0 project

放肆的年华 提交于 2019-12-02 03:59:48
I've got a Solution with many projects. One of them ( Domain ) is a .NET Standard 2.0 project where I made my EF Core DbContext implementation for which I want to enable database migrations . I saw various blogs and Q/A forums where the problem was explained but none of the proposed solutions seem to work for me because of the .NET Core newer version or (probably) for my particular solution configuration. Solution projects Engine (.NET Core 2.1 Console App) Web API (.NET Core 2.1 Library) Application (.NET Core 2.1 Library) Domain (.NET Standard 2.0 Library) WindowsService (.NET Core 2.1

Entity Framework Core - Best way to access a collection on an entity?

泄露秘密 提交于 2019-12-02 03:54:41
问题 I have a simple ASP.NET Core 2.0 + Entity Framework Core project: I have an entity called ApplicationUser , which extends Microsoft.AspNet.Identity.IdentityUser , and the ApplicationUser has a collection of another entity called Books . However, when I try to read the collection of Books from the ApplicationUser after retrieving it from UserManager: ApplicationUser user = await _userManager.GetUserAsync(User); return user.Books; I get an empty collection. If I do this instead: ApplicationUser

Entity Framework Core on Windows IoT running on a RPi 3 (Console Application)

て烟熏妆下的殇ゞ 提交于 2019-12-02 03:48:50
I successfully deployed a .NET Core Console Application to my Windows IoT running on a Raspberry Pi 3. The application pulls data from a webservice and stores them in a database. I used Entity Framework Core for that. When I start the deployed console application (.exe) through the remote powershell everything works except the access to my database running on Azure. When the application tries to read from the database it throws the following exception: System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. ---> System

Get Object with deep level of related entity

▼魔方 西西 提交于 2019-12-02 03:14:17
问题 Suppose I have a entity class with one to one relationship as below: public class Transaction { public int TransactionID { get; set; } public Double Amount { get; set; } public int TransactionDetailID { get; set; } public virtual TransactionDetail TransactionDetailFk { get; set; } } public class TransactionDetail { public int TransactionDetailID { get; set; } public DateTime PostedDate { get; set; } public int TransactionTypeID { get; set; } public int TransactionCategoryID { get; set; }

AspNet EF referencing foreign key to field

狂风中的少年 提交于 2019-12-02 02:39:18
Im having two models: public class Customer { public int Id { get; set; } public int Number { get; set; } public int ParentNumber { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string Country { get; set; } public string Language { get; set; } } and public class Batch { public int Id { get; set; } public int Number { get; set; } public string FileName { get; set; } public string ArticleNumber { get; set; } public string ArticleDescription { get; set; } public int Weight { get; set; } public DateTime ProductionDate { get

ASP.NET MVC Core Cascading DropDownList

一笑奈何 提交于 2019-12-02 02:01:29
问题 I'm having trouble finding a tutorial / video that shows how to implement Cascading DropDownList from a Database using EntityFramework. I'm using ASP.NET MVC Core, EntityFramework Core with C#. As of now, I'm able to retrieve the data from my database to my 3 DropDownList fine. What I would like to be able to accomplish is to have the user select a State first which would then display all Cities related to that State. Then after user has selected a City it would display the Zip Code(s)

DescriptionAttribute not available in DNX Core 5.0

混江龙づ霸主 提交于 2019-12-02 01:09:18
I'm having an issue with DescriptionAttribute in ASP.NET 5 project. I wanted to use DescriptionAttribute for my enum class, but the project cannot be built due to missing reference in DNX Core 5.0 Here's my project.json file { "userSecretsId": "", "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final", "Microsoft.AspNet.Identity