entity-framework-core

EF Core and Multiple Databases

天大地大妈咪最大 提交于 2020-02-23 09:31:07
问题 I have a legacy system with three databases Vendor CustomCode LogData Vendor contains control and log data from our Vendors app. CustomCode contains lots of views and stored procedures that joins to Vendor and LogData LogData contains results from our CustomCode processes. eg: Daily/Weekly/Monthly summaries and results. I'm writing a website that will plot data on a map. The list of units is from a view in CustomCode. The Summary record is from LogData, and the individual log points are

EntityFramework Core - Copying an entity and placing it back into the database

≯℡__Kan透↙ 提交于 2020-02-21 11:02:11
问题 Is there a best practice for doing a copy of an entity, making some changes to it based on user input, and then re-inserting it into the database? Some other Stackoverflow threads have mentioned that EF will handle inserting new objects for you even if the same primary key exists in the database, but I'm not quite sure that's how EF Core is handling it. Whenever I try and copy an object I get an error of Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to

EF 3.1: Overcome LINQ GroupBy SQL translation problem [duplicate]

[亡魂溺海] 提交于 2020-02-21 06:11:38
问题 This question already has an answer here : Problem with EF OrderBy after migration to .net core 3.1 (1 answer) Closed 27 days ago . In MS SQL Server I have a table that contains a history of calls to contacts (that is another table). Accessed by EF, The Entities are the following: public partial class CallbackHistory { public int HistoryId { get; set; } public int CompanyId { get; set; } public int CallerId { get; set; } public DateTime LastCallTimeStamp { get; set; } public virtual

How to delete whole database and reset the change tracker with EF Core using SQLite

陌路散爱 提交于 2020-02-21 04:57:27
问题 I have a server client architecture where the server provides a Rest API for the clients to synchronize the whole database data. They save it to their local SQLite database. The model is in a shared project and can change sometimes. Therefore the clients need to update their local SQLite database schema. This of course only happens after updating client's software (database file stays unchanged). It's simply achieved by generally deleting the database file and recreating it afterwards.

Storing data between requests in dbcontext

*爱你&永不变心* 提交于 2020-02-20 08:06:25
问题 I have a page with server side rendering using razor, where you can add a couple of elements from different lists, fill some fields and create a request from it on submit. Each time an item is added/taken from any list, I send a post with submit button to a specific action, e.g. "CustomerSelected". I do this, because I need to recreate additional view components for the added item. In these methods I would like to add added objects to the db context, so on submit I can just say SaveChanges()

Storing data between requests in dbcontext

依然范特西╮ 提交于 2020-02-20 08:06:08
问题 I have a page with server side rendering using razor, where you can add a couple of elements from different lists, fill some fields and create a request from it on submit. Each time an item is added/taken from any list, I send a post with submit button to a specific action, e.g. "CustomerSelected". I do this, because I need to recreate additional view components for the added item. In these methods I would like to add added objects to the db context, so on submit I can just say SaveChanges()

Changes in IDENTITY column after EF core 3

妖精的绣舞 提交于 2020-02-16 02:39:32
问题 Until EF core version used in .donet core 2.2, after the .Add command, EF fills the key column with a big negative number. After 3.0 upgrade this does not happens anymore. Here is the code: var appointment = new Appointment { Date = DateTime.Today, ProfessionalId = schedule.ProfessionalId }; await service.AddAsync(appointment); string message = null; if (service.AddLastPrescription(appointment.Id, schedule.PacienteId)) .... The problem is that now the "appointment.Id" is zero and the call to

Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement “in Entity Framework core”

折月煮酒 提交于 2020-02-14 06:29:49
问题 Here's my EF Core code: int page = 1, rowPerPage = 5; int count = ctx.Specialty.Count(); int start = page * rowPerPage; var Select = ctx.Specialty.OrderByDescending(u => u.IdS) .Skip(start) .Take(rowPerPage) .AsEnumerable(); I am using SQL Server 2008 and Visual Studio 2017, and I installed SQL Server 2017 as well. My project is ASP.NET Core. Error: Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement I think the problem is SQL Server 2008. How can I tell my

Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement “in Entity Framework core”

随声附和 提交于 2020-02-14 06:29:45
问题 Here's my EF Core code: int page = 1, rowPerPage = 5; int count = ctx.Specialty.Count(); int start = page * rowPerPage; var Select = ctx.Specialty.OrderByDescending(u => u.IdS) .Skip(start) .Take(rowPerPage) .AsEnumerable(); I am using SQL Server 2008 and Visual Studio 2017, and I installed SQL Server 2017 as well. My project is ASP.NET Core. Error: Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement I think the problem is SQL Server 2008. How can I tell my

Seed entity with owned property

时光怂恿深爱的人放手 提交于 2020-02-14 02:45:27
问题 I am trying to seed an user entity in my database. The User entity has an owend property EmailPermissions . When I run the command dotnet ef migrations add Initial; I get the error The seed entity for entity type 'User' cannot be added because it has the navigation 'EmailPermissions' set. To seed relationships you need to add the related entity seed to 'EmailPermissions' and specify the foreign key values {'UserId'}. but since EmailPermissions is an owned entity I didn't give it an explicit