entity-framework-6

ProviderManifestToken 2008 or 2012

不打扰是莪最后的温柔 提交于 2019-12-03 15:52:30
The application: .NET 4.5 C# Uses EF6 with database first approach Supports SQL Server 2008R2, 2012 and 2014 This question is regarding the ProviderManifestToken attribute of the auto-generated edmx file. Depending on which version of the database is used (different developers have different version of the database) to update the model from the database, the value of the ProviderManifestToken attribute either gets set to 2008 or 2012. Until we discontinued support for SQL Server 2005, we made sure that the value of this attribute remained 2005 (see this SO article for more information). I am

Stored Procedure returns incorrect scalar value of -1, instead of return value

夙愿已清 提交于 2019-12-03 15:45:41
I am trying to return a scalar value from a stored procedure. I actually want to return the ID of a newly created record, but I have simplified my problem down to a stored procedure that takes an int and attempts to return that same int . This always returns -1. Thank you very much for your help. Web API Controller call var idtest = dbconn.my_return_int(123); The stored procedure: ALTER PROCEDURE [dbo].[my_return_int] @ID int AS BEGIN SET NOCOUNT ON; DECLARE @return as int SET @return = -999 RETURN @return END The Context generated stored procedure call public virtual int my_return_int

DDD - Consistency of Entity Across Bounded Context & Different Schemas in Database

荒凉一梦 提交于 2019-12-03 15:26:34
I am implementing DDD with Entity Framework Code First. My Domain Model is persisted as it is without any mapping layer. I am following approach suggested during Tech-Ed by Julie Lerman. Each bounded context maps to different schema within same database. If same entity say, Customer appears across different bounded contexts how do we maintain consistency of data for Customer entity? Only a single bounded context will be the system of record for your entity. If you cannot get away with simply an Id in the other BCs then you can include a subset of the entity (usually not all the properties) as

Create Foreign Key using Data Annotations

自闭症网瘾萝莉.ら 提交于 2019-12-03 14:46:16
In the code below, I need to set a foreign key constrant on ParentInfoAddProperties.ParentQuestionAnswersId so that it is dependent on ParentQuestionAnswers.Id (which is a Primary Key). I am attempting to do so using data annotations but Entity Framework 6 wants to create a new Foreign Key column in my ParentQuestionAnswers table which references the ParentInfoAddProperties.Id column not the ParentInfoAddProperties.ParentQuestionAnswersId column. I do not want Entity Framework to create a new foreign key column. I'd greatly appreciate if someone can explain what data annotations or (if

How to use generic type with the database Context in EF6 Code First

我是研究僧i 提交于 2019-12-03 14:43:13
问题 For example, let say I have 4 different entity that each implement a Add() method that add the entity to the database : public class Profile { ... public void Add() { this._dbContext.Profile.Add(this); this._dbContext.SaveChanges(); } ... } Now I would like to have a generic class that implement this kind of behavior in one abstract class instead of X number of classes. So I tried the following : public abstract class Entity<TEntity> where TEntity : class { protected DbContext _dbContext;

MVC 5 Entity Framework 6 Execute Stored Procedure

随声附和 提交于 2019-12-03 13:56:56
问题 I'm stuck. I have an existing application with an extremely large database and extensive library of stored procedures and functions. All I want to do is use a DbContext to execute a stored procedure and return a set of data or map to one of the entities in the context. Is that something magical I haven't discovered on the net somewhere? Someone, anyone, please help. Here's what I've got so far (and it doesn't return anything, the result is -1): var contacts = db.Database.ExecuteSqlCommand(

ASP.NET Identity - Error when changing User ID Primary Key default type from string to int AND when using custom table names

若如初见. 提交于 2019-12-03 13:39:29
I'm using Microsoft.AspNet.Identity 2.0.0-beta1 and Entity Framework 6.1.0-beta1 (released 11 Feb 2014). I'm getting the following error when I try to change the default type of User ID Primary Key from string to int AND when I try to use custom table names (so User.MyUsers instead of dbo.AspNetUsers): " The entity types 'IdentityUser' and 'ApplicationUser' cannot share table 'MyUsers' because they are not in the same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them. " I can successfully change the default type of User ID PK from

Example of using asp.net 5 MVC 6 with Identity and EF 6

守給你的承諾、 提交于 2019-12-03 13:38:41
问题 I'm setting up a new project using asp.net 5 and MVC 6, but I want to use Entity Framework 6 due to the missing features in EF 7. I setup EF 6.1.3 and that is working. Identity 3.0 depends on EF 7 so I have removed that and referenced in Identity 2.2 but I'm not sure where to go from here. 回答1: I'm not sure how this will be handled in the final release of ASP.NET 5, but in the case of ASP.NET 5 RC1 we have the following: Firstly, you should go with Identity 3.0, as there is no way to use

How to use SqlAzureExecutionStrategy and “Nolock”

╄→гoц情女王★ 提交于 2019-12-03 13:07:07
To deal with SQL timeouts I'm trying to use SqlAzureExecutionStrategy ( https://msdn.microsoft.com/en-us/data/dn456835.aspx ) The problem I am running into is it prevents "user initiated transactions" which seem to be the recommended way to implement "with (nolock)" in EF ( http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx , NOLOCK with Linq to SQL ). example code public AspnetUser GetAspnetUserByUserName(string userName) { using (var tx = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel

EF & Automapper. Update nested collections

 ̄綄美尐妖づ 提交于 2019-12-03 12:52:59
问题 I trying to update nested collection (Cities) of Country entity. Just simple enitities and dto's: // EF Models public class Country { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<City> Cities { get; set; } } public class City { public int Id { get; set; } public string Name { get; set; } public int CountryId { get; set; } public int? Population { get; set; } public virtual Country Country { get; set; } } // DTo's public class CountryData : IDTO {