entity-framework-6

How to integrate PostgreSql with EntityFramework 6.0.2?

别等时光非礼了梦想. 提交于 2019-12-07 11:41:41
问题 I am receiving following error The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql, Version=2.0.14.2, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or

Can I use UseCSharpNullComparisonBehavior for a single query?

纵饮孤独 提交于 2019-12-07 11:25:49
问题 I have a query that used to be a stored procedure and was converted to an EF query. It is timing out now. Using SQL Profiler, I can see the only difference in the SQL generated is the new behavior where EF turns entity.Property == value into (entity.Property = @value OR (@value IS NULL AND entity.Property IS NULL)) . I know I can turn this off for the entire context by setting UseCSharpNullComparisonBehavior = false , but I really only want to do it for this one query. Is that possible? Or,

Calling service/repository methods in ASP.Net Core middleware

独自空忆成欢 提交于 2019-12-07 11:22:25
问题 ASP.Net Core noob here...I am using an ASP.Net Core WebAPI core project using DNX451 with EF 6. I have a requirement to implement API Key auth in our service. To do this I have created middleware that gets information from the request and proceeds with authentication. It is SUPPOSED to go to the database, get the key to match, and then return and do the validation. Here is the middleware implemented to look at the context and get the APIKey AuthenticationHandler public class

Entity Framework One-Many TPH Mapping

泪湿孤枕 提交于 2019-12-07 11:12:03
问题 I'm using a data structure similar to this where type of animal is determined from a discriminator column in the table: public class Farm { public int Id { get; set; } public virtual ICollection<Pig> Pigs { get; set; } public virtual ICollection<Cow> Cows { get; set; } } public class Animal { public int Id { get; set; } public int FarmId? { get; set; } public virtual Farm Farm { get; set; } public string Name { get; set; } } public class Pig : Animal {} public class Cow : Animal {} Mapping:

Issues Generating .edmx EF6 in Visual Studio 2013

╄→尐↘猪︶ㄣ 提交于 2019-12-07 11:02:46
问题 I am trying to generate my edmx file for my database in Visual Studio 2013 against either a mssql 2012 or 2008 database server and table set. The edmx file generates with out issue, and everything looks fine until i try to compile the project. Every single object representing a database table errors out with the following messages. A using namespace directive can only be applied to namespaces; 'System' is a type not a namespace The type name 'Collections' does not exist in the type 'Model

Entity Framework - The migrations configuration type was not be found in the assembly

久未见 提交于 2019-12-07 07:40:22
I have multiple dbcontexts in a C# project and I'm trying to enable migrations, when I specify the full command ie: "Enable-Migrations -ContextTypeName Models.Account.AccountDetailDbContext" A migrations folder is created, with the configuration class I then get a message: "Checking if the context targets an existing database..." And then "The migrations configuration type 'Portal.WebUI.Migrations.Configuration' was not be found in the assembly 'Portal.WebUI'." Even though it has just created the file it can't find it. Can anyone help on this please? I have the correct project selected in the

A first chance exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll

狂风中的少年 提交于 2019-12-07 06:13:04
问题 I am trying to call a stored procedure using entity framework 6. I get an error on the output message. A first chance exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll using (var context = new PartnerPortalEntities2()) { var outputParameter = new ObjectParameter("result", typeof(string)); var spresults = context.assignRoles_CreateAccountAndContacts(user.Id, role, user.AccountId, user.AccountName, user.ContactId, user

Implementing an ICollection<ISomething> with a concrete type to satisfy Entity Framework

泪湿孤枕 提交于 2019-12-07 05:25:53
问题 So, this is kind of an obtuse question, but let me see if I can lay it out relatively simply. Lets say I have the following interface: public interface IFoo { ICollection<IBar> Bars { get; set; } } Which I then implement with: public class Foo : IFoo { public virtual ICollection<IBar> Bars { get; set; } } Only Entity Framework can't work with interfaces, so it pretty much completely ignores this navigation property. In order to get EF to recognize it, I need to change it to: public virtual

How to add EntityObject Generator in Visual Studio 2015?

十年热恋 提交于 2019-12-07 03:41:53
问题 I have installed the latest Entity Framework version (EntityFramework.6.1.3) in VS2015. I have added the EF in the project and deleted the 2 .tt files ( edmx_file_name.tt and edmx_file_name.Context.tt ) as they were from the DBContext. Now I am trying to add the EF 6.x code generation template by open the model in the EF Designer, right-click on the design surface and select Add Code Generation Item . To add the Code Generation in ObjectContext i need to install the EF 6.x EntityObject

The item with identity 'Id' already exists in the metadata collection. Parameter name: item

那年仲夏 提交于 2019-12-07 02:05:35
问题 All of my entities have a base class: public class Entity<TKey> : IEntity<TKey> { dynamic IEntity.Id { get { return this.Id; } set { this.Id = value; } } public TKey Id { get; set; } } For example Status entity: [MetadataType(typeof(StatusMetadata))] public partial class Status : Entity<byte> { public string Title { get; set; } } When I run the query against the database I get the following error: "The item with identity 'Id' already exists in the metadata collection. Parameter name: item".