entity-framework

WCF / EF / SQL Server / VS2017 / C# : multi-tier application gets error when deployed to local IIS 10.0 as hosting server

僤鯓⒐⒋嵵緔 提交于 2020-07-10 10:27:27
问题 I am trying to deploy a Windows desktop application with service layer, logic layer and data layer. The data layer uses SQL Server with EF 6.2. The UI client layer is a Windows Forms application. The application works great in test debug mode when the service is hosted by the WcfSvcUtil.exe application with a service alias in IIS - no errors and all data retrieval and updates are working in test. Now, I have published the Service layer, logic layer and data layer as an empty web site to be

Dbcontext has been disposed when using “using Statement”

天涯浪子 提交于 2020-07-10 04:43:29
问题 Error message: The operation cannot be completed because the dbcontext has been disposed. Can somebody explain why and where my DbContext is getting disposed while I perform the update? Context file: using System.Data.Entity; namespace OnlineTest { internal class OnlineTestContext : DbContext { private OnlineTestContext() : base("name=OnlineTest") { } private static OnlineTestContext _instance; public static OnlineTestContext GetInstance { get { if (_instance == null) { _instance = new

ef core - two one to one on one principal key

a 夏天 提交于 2020-07-09 13:23:48
问题 Got the following datamodel: class EntityA { Guid Id { get; set; } //Property1 and Property2 will never be the same EntityB Property1 { get; set; } EntityB Property2 { get; set; } } class EntityB { int Id { get; set; } EntityA EntityAProperty { get; set; } } But I can't manage to configure the relation. EntityA references two different EntityB. Please give me some advise on how to configure it. Tried something like (for property1 and property2): e.HasOne(x => x.Property1) .WithOne()

Selecting distinct entity values based on string field name

偶尔善良 提交于 2020-07-07 14:24:27
问题 Is it possible to select distinct property values of an entity where the column name is not known in advance - received by the method as a string from the client. For filtering purposes I want to make a HTTP POST Ajax request to the server from the browser which will contain the field name as a key, and this will be available to the server as a string. I know I am going to have to manually map any differences between the ViewModel and the POCO class used by Entity Framework, but is it

Does an equivalent to Database.CompatibleWithModel(bool) exist in EF Core

不羁的心 提交于 2020-07-06 20:21:57
问题 I'm working on a project that uses EFCore 2.1.0-preview1-final code first approach. Like in EF6 (and previous versions) I want to ensure the compatibility of my DbContext (and models) to the database. In EF6 it was enabled by default and it was possible to deactivate it with Database.CompatibleWithModel(false);. As far as I know EF uses the __MigrationHistory table where the model information was stored. EFCore has no such column in __EFMigrationsHistory table that could provide such

Entity Framework Core, deleting items from nested collection

南笙酒味 提交于 2020-07-06 11:11:24
问题 I have two classes public class InvoiceRow { public int Id { get; set; } public int InvoiceId { get; set; } public int ProductId { get; set; } public virtual Product Product { get; set; } public int Amount { get; set; } } public class Invoice { public int Id { get; set; } private ICollection<InvoiceRow> _rows; public virtual ICollection<InvoiceRow> Rows => _rows ?? (_rows = new List<InvoiceRow>()); } I use Update method in the repository class public void Update(Invoice record) { dB.Invoices

Entity Framework Database First .Net Core

[亡魂溺海] 提交于 2020-07-06 10:45:41
问题 I have a .Net Standard 2.0 class library project and I want to add Entity Framework to it. I have added the Entity Framework Core package to the project but no Entity Framework Templates appear when I try to add a new item to the project. I have looked on the web and all I can seem to find is instructions for Code First! How do I get the database first functionality back? 回答1: EF Core does not, and will never, support the EDMX-based Database First workflow with the designer. EF Core stores

Entity Framework Database First .Net Core

流过昼夜 提交于 2020-07-06 10:44:34
问题 I have a .Net Standard 2.0 class library project and I want to add Entity Framework to it. I have added the Entity Framework Core package to the project but no Entity Framework Templates appear when I try to add a new item to the project. I have looked on the web and all I can seem to find is instructions for Code First! How do I get the database first functionality back? 回答1: EF Core does not, and will never, support the EDMX-based Database First workflow with the designer. EF Core stores

DatabaseGeneratedOption.Identity not generating an Id

和自甴很熟 提交于 2020-07-06 09:14:48
问题 Using EntityFramework code-first, I've created a simple Foo table. Here's my entity: public class Foo { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual string Id { get; set; } public virtual string Name { get; set; } } However whenever I try to insert a new row, I get a Cannot insert the value NULL into column 'Id' . Why is this happening when I've added a DatabaseGenerated attribute? Deleting and recreating my table makes no difference. 回答1: Identities for string column

Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship

馋奶兔 提交于 2020-07-06 09:06:56
问题 I have an entity with a foreign key relationship to an asp.net membership provider users table. This portion of the model looks like this: I can't seem to assign the foreign key relationship when inserting the Users table record, the record containing the foreign key to the aspnet_Users table. I keep getting the error: An item with the same key has already been added. The code I'm using looks like: UserAdmin userToAdd = new UserAdmin(); ... userToAdd.aspnet_Users = membershipUser; //line