entity-framework-core

Stop EF Core from using Merge to Insert

左心房为你撑大大i 提交于 2020-01-05 07:16:26
问题 I am converting my application to .NET Core. In doing so, I am running into issues with EF Core and inserts. If I insert 1 or 2 rows then EF Core performs a normal SQL INSERT statement. But when I have 3 or more rows, it switches to a MERGE statement, which then fails with: The column reference "inserted.MyKeyColumn" is not allowed because it refers to a base table that is not being modified in this statement. My guess is that this is due to the fact that the query is actually running on a

registering DbContext with multiple parameters

蓝咒 提交于 2020-01-05 04:51:05
问题 I'm trying to inject TenantProvider into DbContext public class AppDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, long> { public int? _tenantId; public ITenantProvider _tenantProvider; public AppDbContext( DbContextOptions<AppDbContext> options, ITenantProvider tenantProvider ) : base(options) { _tenantProvider = tenantProvider; } but I don't understand how to register it correctly - if I put the breakpoint in the constructor - tenantProvider is null . The bit from Startup.cs

Entity Framework Core generates two select queries for one-to-many relationship

大憨熊 提交于 2020-01-05 04:28:08
问题 I'm building an EF Core provider for the Google Spanner db. I've bumped with an issue when trying to select an entity with one to many relationship. For example, lets say I have the following entities: public class Player { public string PlayerId { get; set;} public string Name { get; set;} public List<Game> Games { get; set;} } public class Game { public string GameId { get; set; } public string PlayerId { get; set; } public Player Player { get; set;} } Each Game is related to one Player and

Using EF Core 2.2 to decrypt a string using SQL Server DECRYPTBYKEY

若如初见. 提交于 2020-01-05 04:19:07
问题 Basically I have a POCO model that has a encrypted string. Using EF core 2.2. We use DECRYPTBYKEY to decrypt strings using SYMMETRIC KEY. I am using DBSet.FromSQL to pass in SQL query which calls open symmetric key, get the data including the decrypted value, close symmetric key. FromSQL only allows you to bring back an entity rather than a string by itself. I have tried adding an decrypted string value on the model and have tried to then set that in FromSQL query. This actually populates ok

IMutableEntityType.GetProperties() doesn't include a property that I want

最后都变了- 提交于 2020-01-05 03:17:07
问题 I have a bunch of models that all make use of a class that I have created. They have properties of type Measurement . This Measurement class is not in itself an entity or a model that I want mapped to a database table. It's simply a type for passing around values and units in a pair, along with a bunch of methods and operators for managing operations on those values and units. I have created a ValueConverter so that I can represent the properties of this type in my models as strings in the

Group by hour in IQueryable

拜拜、爱过 提交于 2020-01-04 13:48:34
问题 In my project I receive some data from an SPS all x seconds. Every y minutes I archive the current Data in a database so I'm able to show statistics. The data I receive gets put in a model. Something like this but much more complex: public class Data { public DateTime ArchiveTime { get; set; } public float TempC { get; set; } public float CO2Percent { get; set; } } I have a repository for the database that returns all entries in a certain time span. See this code: // Context is my DbContext

Group by hour in IQueryable

不羁岁月 提交于 2020-01-04 13:47:08
问题 In my project I receive some data from an SPS all x seconds. Every y minutes I archive the current Data in a database so I'm able to show statistics. The data I receive gets put in a model. Something like this but much more complex: public class Data { public DateTime ArchiveTime { get; set; } public float TempC { get; set; } public float CO2Percent { get; set; } } I have a repository for the database that returns all entries in a certain time span. See this code: // Context is my DbContext

“Column names in each table must be unique.” during database update

╄→尐↘猪︶ㄣ 提交于 2020-01-04 09:39:21
问题 I am quite new to ASP.NET at all, however this is my first app with ASP.NET Core. I have problem with updating database after creating the migration. While I type command: dotnet ef database update , I get error: Column names in each table must be unique. Column name 'PortalUserId' in table 'Adverts' is specified more than once. I think the problem is with my model structure, but I do not know what I am doing wrong. When I was developing with ASP.NET MVC 5 everything was Ok. Here is my Model

Entity framework: disable delete globally

我们两清 提交于 2020-01-04 07:47:13
问题 We are starting a new application. We want to use Entity Framework. We are little afraid of deleting sql rows accidentally (especially by set related data accidentally etc.) I thought to disable every delete, since we just mark every row with "validUntil" column and never delete rows. I saw that it can done by roles in sql, but I want that all logic and control will be just in code. Maybe in Entity Framework core there is new feature to enable that? I know that it can still write row sql with

Visual Studio for Mac connection to remote MS SQL Server failed

时光怂恿深爱的人放手 提交于 2020-01-04 06:55:24
问题 I'm using Visual Studio for Mac 2017 on macOS Sierra with Microsoft EntityframeworkCore and I'm trying to connect to a remote MS SQL Server. If I start the project in Visual Studio on my Windows machine, everything works fine. But the same project on my Mac tells me "A call to SSPI failed" when I try to get data from the SQL Server. I can connect to the SQL Server using the "Oracle SQL Developer" tool on my Mac. So the issue is somewhere in Visual Studio. The connection string: Server