entity-framework-core

Entity Framework Core 2.0 migrations update database with seed data throwing error

眉间皱痕 提交于 2019-12-11 15:28:16
问题 I am using EF Core 2.0 code first migration. I am trying to run the migration sin to the new database. I am using seed data. I am getting error if i use seed data and no error if i comment out the seed data method. Not sure what is the problem. Can anyone please help? Error: System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'WorkflowBranches' in the database. The tables are created, but no records appear in the migrationhistory table, even though I have around

Stored Procedure in dot net core

本小妞迷上赌 提交于 2019-12-11 15:18:52
问题 Below is my method, which calls a stored procedure. public List<int> GetActivityListforUser(string userId) { IList<int> results = new List<int>(); context.LoadStoredProc("dbo.GetRegionOrganizationActivities") .WithSqlParam("userId", userId) .ExecuteStoredProc((handler) => { results = handler.ReadToList<int>().ToList(); }); return results.ToList(); } My stored procedure dbo.GetRegionOrganizationActivities , returns only one column Id, which is the required result up on passing the parameter

Why aren't related entities loaded on .Include()?

独自空忆成欢 提交于 2019-12-11 15:18:33
问题 Can anybody tell me why the related Article entities are not being loaded on .Include(a => a.Article) ? They are always NULL even though ArticleId does indeed have a value. The relationship between FrontPageItem and Article is 1-0..1. An Article can exist without any connection to a FrontPageItem , but a FrontPageItem must have one Article . In a rather ugly workaround, I have resorted to foreach -ing through all the returned items in the list and adding Article manually, as you can see in my

How to Connect to Local SQL Server From Linux Docker Container

…衆ロ難τιáo~ 提交于 2019-12-11 14:44:54
问题 I am trying to connect to my local instance of SQL Server using a linux Docker container running on my Windows machine. I can connect successfully using Data Source=localhost when running under Windows. I've discovered that localhost is not supported in a connection string on linux, so here is what I've also tried and failed with: Data Source=localhost Data Source=localhost,1433 Data Source=127.0.0.1 Data Source=127.0.0.1,1433 Data Source=127.0.0.11 Data Source=127.0.0.11,1433 Data Source=172

Database operation expected to affect 1 row(s) but actually affected 50(db sequence next number) row(s)

梦想的初衷 提交于 2019-12-11 14:39:20
问题 I use entity framework 2.2.6. I have AddOrUpdate method. When client try to operate(insert or update) on entity I check if entity exist on db by unique values and I set old data id value to new data id value and I set it as updated. If not exist I set it as insert public void AddOrUpdate(TEntity entity, Expression<Func<TEntity, bool>> predicate) { var oldEntity = Get(predicate); DetachEntry(oldEntity); if (oldEntity != null) { var idProperty = entity.GetType().GetProperties().First(x => x

IServiceCollection does not contain a definition or extension for AddNpgsql

我怕爱的太早我们不能终老 提交于 2019-12-11 13:54:16
问题 I'm trying to use PostgreSQL for the first time and having a little trouble getting it to build without errors unless I lock into RC2 packages which is fine. After locking into the RC2 packages, I have one error that I can't seem to shake that I could use help troubleshooting: ERROR Startup.cs(22,18): error CS1061: 'IServiceCollection' does not contain a definition for 'AddNpgsql' and no extension method 'AddNpgsql' accepting a first argument of type 'IServiceCollection' could be found (are

How to parse byte[] array from model with IFormFile from viewmodel for file uploading controller?

∥☆過路亽.° 提交于 2019-12-11 13:35:09
问题 I have Core MVC application, when for specific entity I have following model: public class Aktualnosci { public long ID { get; set; } public string Tytul { get; set; } public string Tresc { get; set; } public DateTime Dzien { get; set; } public byte[] AktualnosciImage { get; set; } } For uploading the image I am using IFormFile property in my viewmodel, that is called by controller, according to the documentation from >>HERE<<: public class AktualnosciCreateVM { public long ID { get; set; }

How to add the support for structured annotations to the EF Core SqlServer target builder?

旧城冷巷雨未停 提交于 2019-12-11 13:18:12
问题 It is easy to add plain string annotations to the EF model with HasAnnotation method that accept object type of argument, but trying to add structured annotations you will get errors on build migration: modelBuilder.Entity<Group>().HasAnnotation($"{GetType().FullName}.Constraint3", new ValueTuple<string,string>( "aaa", "bbb" )); The current CSharpHelper cannot scaffold literals of type 'System.ValueTuple`2[System.String,System.String]'. Configure your services to use one that can.

How can a JSON_VALUE be converted to a DateTime with EF Core 2.2?

不羁的心 提交于 2019-12-11 12:28:53
问题 I am mapping JSON_VALUE using the technique from How to write DbFunction's translation. Since not all values in the JSON are strings, conversion is sometimes necessary. When converting to int , everything is fine: var results = context.Set<SampleTable>() .Where(t1 => Convert.ToInt32( JsonExtensions.JsonValue(t1.SampleJson, "$.samplePath.sampleInt")) > 1); .ToList(); The resulting SQL is: SELECT * FROM [SampleTable] AS [t1] WHERE (CONVERT(int, JSON_VALUE([t1].[SampleJson], N'$.samplePath

EF7 commands do not work in VS2015 CTP 6

守給你的承諾、 提交于 2019-12-11 12:28:37
问题 I'm trying to run ef7 migration on fresh asp.net 5 preview project. Steps I took: Created fresh project based on template "ASP.NET 5 preview starter web" Build it Try command Add-Migration in Package Manager console Result: The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. I also try this command: Install-Package EntityFramework.Commands -Pre I think for VS 2015 project is redundant, it executed but still Add-Migration was not