Code first Unique constraint on multiple columns
Say I want a Microsoft SQL Server entity as follows: CREATE TABLE [dbo].[Entity]( [ID] [int] IDENTITY(1,1) NOT NULL, [COL1] [nvarchar] NOT NULL, [COL2] [nvarchar] NULL, [COL3] [nvarchar] NULL, CONSTRAINT [PK_Entity] PRIMARY KEY CLUSTERED Then…
DbContext lifetime in desktop app with SQLite
I am creating a small data-driven desktop application using .NET 5 with WPF, ReactiveUI, Dynamic Data, and EF Core 5. The app uses a local SQLite database to store all persisted state, and relies heavily on dependency injection. I would like to share…
Having trouble with foreign key in entity, can't track because the FK is already part of another object
Scenario: I have an entity that is central to the business, let's call it Company. Entity Foo has FK CompanyID, as does entity Bar. If, within the same context, I retrieve Foo and create an instance of Bar, then try…