ef-core-2.1

Error when inserting into temporal table using Entity Framework Core 2.1

断了今生、忘了曾经 提交于 2019-12-08 02:27:03
问题 I'm getting the below error when trying to insert into a temporal table using Entity Framework Core 2.1. Cannot insert an explicit value into a GENERATED ALWAYS column in table 'db_test.dbo.Department'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. Below is my table schema CREATE TABLE Department ( DeptID int NOT NULL PRIMARY KEY CLUSTERED, DeptName varchar(50) NOT NULL, ManagerID INT NULL, ParentDeptID int NULL,

Error when inserting into temporal table using Entity Framework Core 2.1

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:13:21
I'm getting the below error when trying to insert into a temporal table using Entity Framework Core 2.1. Cannot insert an explicit value into a GENERATED ALWAYS column in table 'db_test.dbo.Department'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. Below is my table schema CREATE TABLE Department ( DeptID int NOT NULL PRIMARY KEY CLUSTERED, DeptName varchar(50) NOT NULL, ManagerID INT NULL, ParentDeptID int NULL, SysStartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL, SysEndTime datetime2 GENERATED ALWAYS AS ROW

Entity Framework Core 2.1 - Multiple Providers

ぐ巨炮叔叔 提交于 2019-12-06 02:27:25
What is the right way to work with multiple providers? My Example: appsettings.json { "ConnectionStrings": { "Sqlite": "Data Source=database.db" } } Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddDbContext<DatabaseContext>(options => options.UseSqlite(Configuration.GetConnectionString("Sqlite"))); } DatabaseContext.cs public class DatabaseContext : DbContext { public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { } public DbSet<TestModel> TestModel{ get; set; } } A easy way for multiple providers? A solution with only one

Version Conflict detected for Microsoft.EntityFrameworkCore.Install

谁都会走 提交于 2019-12-04 16:48:43
问题 I am getting the following error when adding an asp.net core api to an existing project I am working on. "Version Conflict detected for Microsoft.EntityFrameworkCore.Install/reference Microsoft.EntityFrameworkCore 2.2.1 directly to project to resolve this issue" I tried to add the Nuget package but get further version conflicts across a number of different packages and the process always fails. At first I thought this may be an issue with my project so I started a new solution from scratch

How to Write In Clause with EF FromSql?

扶醉桌前 提交于 2019-12-02 10:22:05
I have an unknown amount of parameters for my inclause. How can I write it so it works with EF Core? var formattedValues = String.Join(",", values.Select(s => "'" + s + "'")); var identifierParam = new SqlParameter("jsonColumn", $"$.{identifierKey}"); var filterValueParam = new SqlParameter("value", $"%{formattedValues}%"); var items = dbContext.Items.FromSql("select * FROM Items WHERE AND JSON_VALUE(Attributes, @jsonColumn) in (@value)", filterValueParam, identifierParam).ToList(); I think it is because each value in the in clause needs it's own Parameter. Since you're using SQL Server, you

How to Write In Clause with EF FromSql?

最后都变了- 提交于 2019-12-02 09:56:12
问题 I have an unknown amount of parameters for my inclause. How can I write it so it works with EF Core? var formattedValues = String.Join(",", values.Select(s => "'" + s + "'")); var identifierParam = new SqlParameter("jsonColumn", $"$.{identifierKey}"); var filterValueParam = new SqlParameter("value", $"%{formattedValues}%"); var items = dbContext.Items.FromSql("select * FROM Items WHERE AND JSON_VALUE(Attributes, @jsonColumn) in (@value)", filterValueParam, identifierParam).ToList(); I think

How do you add the equivalent of the OwnedAttribute using FluentAPI?

让人想犯罪 __ 提交于 2019-12-01 23:26:08
问题 I can't seem to do this without using either the attribute on TrackState or specifying OwnsOne for Publishers + Articles. Is there any way i can globally mark TrackState as an owned type without using the attribute? (for people comming through google: How do you add attributes to entities using fluent api?) (Entities + EF core are in seperate libraries and i do not want a dependency there on EF) public class Publisher { public int Id { get; set; } public string Name { get; set; } public

Optional Parameters with EF Core FromSql

房东的猫 提交于 2019-12-01 23:13:43
Is it possible to use EF Core FromSql to execute a stored procedure that has optional parameters? I have been testing out a simple scenario to use as a template for updating old EF6 calls to EF Core calls. The test example I am using as a proof of concept: CREATE PROCEDURE [dbo].[TestNullableParameters] @addressId int = null, @city nvarchar(100) = null, @createdByUserId int AS BEGIN select * from CRM..Address a where (@addressId is null or a.AddressId = @addressId) and (@city is null or a.City like @city) and a.CreatedByUserId = @createdByUserId END My test code that calls this proc: [Test]

Scaffold-DbContext “The method or operation is not implemented”

﹥>﹥吖頭↗ 提交于 2019-12-01 15:01:29
Not having a great time. PM> command run Scaffold-DbContext "Server=myserver;Database=mysqlserverdb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Tables Settings -verbose Error: The method or operation is not implemented. System.NotImplementedException: The method or operation is not implemented. at Microsoft.EntityFrameworkCore.Scaffolding.ProviderCodeGenerator.GenerateUseProvider(String connectionString) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.GenerateOnConfiguring(String connectionString, Boolean suppressConnectionStringWarning) at

Scaffold-DbContext “The method or operation is not implemented”

允我心安 提交于 2019-12-01 12:54:45
问题 Not having a great time. PM> command run Scaffold-DbContext "Server=myserver;Database=mysqlserverdb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Tables Settings -verbose Error: The method or operation is not implemented. System.NotImplementedException: The method or operation is not implemented. at Microsoft.EntityFrameworkCore.Scaffolding.ProviderCodeGenerator.GenerateUseProvider(String connectionString) at Microsoft.EntityFrameworkCore.Scaffolding.Internal