entity-framework-6

Should all Entity Framework methods use async? [closed]

谁都会走 提交于 2019-12-09 05:50:47
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Is it good practice, in Asp.Net MVC or Asp.Net Web API, to have every controller actions that query the database (even the simplest query) to use async/await pattern? I know using async/await adds complexity, but does adding it worth it? Even for the simplest query? 回答1:

How to use SqlAzureExecutionStrategy and “Nolock”

穿精又带淫゛_ 提交于 2019-12-09 05:34:58
问题 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

EF6 (code first), MVC, Unity, and a service layer without a repository

给你一囗甜甜゛ 提交于 2019-12-09 05:34:41
问题 My application is using SQL Server 2012, EF6, MVC and Web API. It's also using a repository and assorted files such as: DatabaseFactory.cs Disposable.cs IDatabaseFactory.cs IRepository.cs IUnitOfWork.cs RepositoryBase.cs UnitOfWork.cs We already use a service layer between our controllers and the repository for some complicated business logic. We have no plans EVER to change to a different database and it has been pointed out to me that the recent thinking is that EF6 is a repository so why

Support for Table Valued Functions in EF6 Code First?

天大地大妈咪最大 提交于 2019-12-09 05:12:24
问题 Is it possible to call a TVF in EF6 Code First? I started a new project using EF6 Database first and EF was able to import a TVF into the model and call it just fine. But updating the model became very time consuming and problematic with the large read-only db with no RI that I'm stuck dealing with. So I tried to convert to EF6 code first using the Power Tools Reverse Engineering tool to generate a context and model classes. Unfortunately the Reverse Engineering tool didn't import the TVFs.

DropCreateDatabaseIfModelChanges EF6 results in System.InvalidOperationException: The model backing the context has changed

与世无争的帅哥 提交于 2019-12-09 04:15:22
问题 After migrating to Entity Framework 6 I get an error when executing unit tests on the build server. I'm using the DropCreateDatabaseIfModelChanges initializer. When I change it to MigrateDatabaseToLatestVersion everything works, but I want to stick with the former initializer. The error I'm getting is: System.InvalidOperationException: System.InvalidOperationException: The model backing the 'AppContext' context has changed since the database was created. Consider using Code First Migrations

EntityFramework 6 RC1 Include on Many-to-Many property fails

半腔热情 提交于 2019-12-09 03:36:02
问题 I have a many-to-many relationship between Agents and AgentGroups (psuedocode, abbreviated). public class Agent { public virtual List<AgentGroup> AgentGroups { get; set; } } public class AgentGroup { public virtual List<Agent> Agents { get; set; } } At some point in the code, I want to get all AgentGroups, and I want to prefetch/include the Agents for each group. I also want to pre-fill the AgentGroups collection on the Agents. This was working in EF 6 beta, but no longer works in EF 6 rc1:

How to add an EF6 Association to a Candidate Key / Unique Key which is not the Primary Key?

被刻印的时光 ゝ 提交于 2019-12-09 02:36:15
问题 Using Schema First , I have a database structure, as so ExternalDataItems --- edataitem_id PK -- surrogate auto-increment - NOT for FK relation here datahash UX -- Candidate Key / Unique Index (binary(20)) ExternalMaps --- emap_id PK ext_datahash FK on ExternalDataItems.datahash - NOT referencing the surrogate PK and after generating the SSDL/CSDL 1 has this <Association Name="FK_ExtMaps_ExtDataItems"> <End Multiplicity="1" Role="ExternalDataItems" Type="Store.ExternalDataItems" /> <End

Same application, different databases: Entity framework 6.X + MySQL + SQL Server

我的梦境 提交于 2019-12-08 23:17:54
问题 Yesterday I did migration (EF 5.0 => EF 6.0) of web application that uses entity framework to reach MySql and SQL Server databases (particular DbContext to particular databases, NOT any DbContext to any type of database). Compile time things were done without any issues, run-time faced me with exception: The default DbConfiguration instance was used by the Entity Framework before the 'MySqlEFConfiguration' type was discovered. The [DbConfigurationType(typeof(MySqlEFConfiguration))] attribute

Entity Framework 6 inserting duplicate values

被刻印的时光 ゝ 提交于 2019-12-08 19:16:00
问题 I have following two entities: public class Artist { [Key] public string ArtistId { get; set; } public string Name { get; set; } public virtual ICollection<Genre> Genres { get; set; } } public class Genre { [Key] public int GenreId { get; set; } public string Name { get; set; } public virtual ICollection<Artist> Artist { get; set; } } In my program I create some artists and want to save them: using (var context = new ArtistContext()) { var artists = _fullArtists.Select(x => x.Artist); foreach

EF - WithOptional - Left Outer Join?

三世轮回 提交于 2019-12-08 18:20:00
问题 With the following one-to-one models, both with navigation properties:- public class Foo { public int Id { get; set; } public virtual Bar Bar { get; set; } } public class Bar { public int Id { get; set; } public virtual Foo Foo { get; set; } } Foo has an optional Bar . Bar has a required Foo . I have the following mapping on Bar :- HasRequired(x => x.Foo) .WithOptional(x => x.Bar) .Map(x => x.MapKey("FooId")); Which creates the foreign key on the Bar table named 'FooId'. All this works fine,