entity-framework-core

Entity Framework Core 3.1 with NetTopologySuite.Geometries.Point: SqlException: The supplied value is not a valid instance of data type geography

*爱你&永不变心* 提交于 2020-07-09 04:37:27
问题 I have a model that looks like this: public class Facility { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public NetTopologySuite.Geometries.Point Location { get; set; } } Test code for adding a Point: var testFacility = new Facility(); testFacility.Location = new NetTopologySuite.Geometries.Point(13.003725d, 55.604870d) { SRID = 3857 }; //Other values tested with the same error error //testFacility.Location = new NetTopologySuite.Geometries.Point(13

EF Core Migration: Could not load assembly 'AssemblyName'

落爺英雄遲暮 提交于 2020-07-07 05:38:05
问题 The command "Add-Migration InitialCreate" generates the following error message: Could not load assembly 'MathModelApp'. Ensure it is referenced by the startup project 'MathModelApp'. What does the error message mean? I am using netcore 2.1, Target Platform is x86. 回答1: Please go to solution property and check if you selected same project as the startup project in the solution or not. 回答2: Right Click on EndPoint Project Click on the Set As Startup Project 来源: https://stackoverflow.com

EF Core Migration: Could not load assembly 'AssemblyName'

血红的双手。 提交于 2020-07-07 05:35:12
问题 The command "Add-Migration InitialCreate" generates the following error message: Could not load assembly 'MathModelApp'. Ensure it is referenced by the startup project 'MathModelApp'. What does the error message mean? I am using netcore 2.1, Target Platform is x86. 回答1: Please go to solution property and check if you selected same project as the startup project in the solution or not. 回答2: Right Click on EndPoint Project Click on the Set As Startup Project 来源: https://stackoverflow.com

Can I fire an event on connect database in Entity Framework Core?

你说的曾经没有我的故事 提交于 2020-07-07 03:38:04
问题 I've one DbContext with all working to access my Postgresql DB, but I need to run one little SQL command when connection session starts with DB. I need to do this for every interaction. To be more specific, it's a function for set a session variable with user name logged. It's possible to do something to handle that in EF Core? --SOLUTION-- I didn't realized that I could specify a connection directly in OnConfiguring like bricelam says. I need to do this in every connection because it's a

Can I fire an event on connect database in Entity Framework Core?

a 夏天 提交于 2020-07-07 03:37:44
问题 I've one DbContext with all working to access my Postgresql DB, but I need to run one little SQL command when connection session starts with DB. I need to do this for every interaction. To be more specific, it's a function for set a session variable with user name logged. It's possible to do something to handle that in EF Core? --SOLUTION-- I didn't realized that I could specify a connection directly in OnConfiguring like bricelam says. I need to do this in every connection because it's a

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 Core: How to solve Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-06 08:44:28
问题 I'm using Entity Framework Core with Code First approach but recieve following error when updating the database: Introducing FOREIGN KEY constraint 'FK_AnEventUsers_Users_UserId' on table 'AnEventUsers' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors. My entities are these: public class AnEvent { public int AnEventId { get; set; } public DateTime

Can Entity Framework Core run non-query calls?

一世执手 提交于 2020-07-05 10:28:07
问题 Unfortunately my EF application has to call stored procedures I am unable to change. While this is not ideal I can normally get around it. However, I have a stored proc that does return anything. How does EF core deal with this? I know in previous versions you could run ExecuteNonQuery but I haven't been able to find anything similar in EF Core. I normally run my queries through a helper as such, where T is a class that maps to a return type EF can serialize to: context.Set<T>() .AsNoTracking

Can Entity Framework Core run non-query calls?

孤者浪人 提交于 2020-07-05 10:26:57
问题 Unfortunately my EF application has to call stored procedures I am unable to change. While this is not ideal I can normally get around it. However, I have a stored proc that does return anything. How does EF core deal with this? I know in previous versions you could run ExecuteNonQuery but I haven't been able to find anything similar in EF Core. I normally run my queries through a helper as such, where T is a class that maps to a return type EF can serialize to: context.Set<T>() .AsNoTracking