entity-framework-6

async Indexer in C#

淺唱寂寞╮ 提交于 2021-02-20 07:01:56
问题 Recently, we have movied to EF 6 and we have begun to use EF async commands. For example in my repository I have the following method: // Gets entities asynchron in a range starting from skip. // Take defines the maximum number of entities to be returned. public async Task<IEnumerable<TEntity>> GetRangeAsync(int skip, int take) { var entities = this.AddIncludes(this.DbContext.Set<TEntity>()) .OrderBy(this.SortSpec.PropertyName) .Skip(skip) .Take(take) .ToListAsync(); return await entities; }

Entity Framework bulk insert with transaction management - Performance

£可爱£侵袭症+ 提交于 2021-02-20 04:24:29
问题 I followed the answer in the following link for improving the performance of entity framework for bulk inserts and updates. Improving bulk insert performance in Entity framework Made save changes in batch of 1000 regeneration of the DbContext object after every save changes I got the performance boost as expected. But I have a requirement of rolling back the transaction while exception condition while performing bulk insert. This becomes issue when we re initialize the DbContext object. Is

Why ASP.NET MVC app doesn't recognize user role changes right after modification?

无人久伴 提交于 2021-02-19 05:52:06
问题 I have an ASP.NET MVC hybrid app which has an ApiController besides the MVC Controllers. I'm using role based authorization attributes within both the MVC Controllers and the ApiController both at the controller level and sometimes on method level. I'm using Entity Framework 6 with Model based design. The Controller level authorizations: [Authorize(Roles = "Administrator,RegularUser")] public class EngineController : ApiController { or [System.Web.Mvc.Authorize(Roles = "Administrator

How to choose DbConfigurationType programmatically?

强颜欢笑 提交于 2021-02-18 19:34:34
问题 I have a DbContext : [DbConfigurationType(typeof(MySqlEFConfiguration))] public class MyDbContext : DbContext { public DbSet<MyClass> MyClasses { get; set; } } Now, what if I want to be able to use another DbConfigurationType , according to AppSettings value? So that, I change AppSettings value from MySQL to MSSQL and it becomes: [DbConfigurationType(typeof(MsSqlEFConfiguration))] public class MyDbContext : DbContext { public DbSet<MyClass> MyClasses { get; set; } } Of course, I can create a

LINQ deferred (or immediate?) execution

♀尐吖头ヾ 提交于 2021-02-16 14:20:31
问题 Given the following query: List<GetMultipleLookupListsOutput> data = await _masterListTranslationsRepository .GetAll() //<- it returns IQueriable .GroupBy(q => q.ListLabelID) .Select(q => q .OrderByDescending(w=>w.ISOLanguageCode == isoLanguageCode) .ThenByDescending(w=>w.ISOLanguageCode == "en-US")) .Select(q => q.FirstOrDefault()) // DB call ? .GroupBy(q=>q.ListLabels.Lists.ListName) .Select(q => new GetMultipleLookupListsOutput { ListName = q.Key, LookupLists = q .OrderByDescending(w => w

Entity Framework 6 - Attaching a graph of entities queried with AsNoTracking

我的未来我决定 提交于 2021-02-11 13:47:06
问题 I am retrieving a list of entities from a table FattureFornitori , and loading also a collection owned by them (Voci, plural form - Voce, singular form) and a reference from each Voce to a TipoCosto entity: var db = new DbGestPre(); db.Configuration.ProxyCreationEnabled = false; var s = db.FattureFornitori .Include(x => x.Voci) .Include(x => x.Voci.Select(y => y.TipoCosto)) .AsNoTracking().ToList(); Now, multiple Voci within a single FattureFornitori can reference the same TipoCosto . So,

using multiple dbcontexts in the same database with EF 6

只谈情不闲聊 提交于 2021-02-10 14:30:50
问题 I've seen a few answers that get in the general area of this question, but none that directly gets at what I'm seeing. I've inherited a recent code base with a charter to make the code run faster. It looks to me like each of the tables in the database (one database) is given its own dbcontext. These tables are highly relational and the major issue I keep seeing is that decisions need to be made based on foreign key relationships between tables. With this design approach, every time two tables

Entity Framework trying to add migration of tables that are already in database

南楼画角 提交于 2021-02-10 09:14:00
问题 When trying to run my ASP.NET MVC application locally, everything works fine. But once I've deployed it Azure, it keeps giving me the error: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. So I connected to the remote database using the Package Manager Console in Visual Studio and ran the Update-Database command. This gave me the same error. When I look at the database inside the SQL Server Management Studio, it looks

Entity Framework trying to add migration of tables that are already in database

纵饮孤独 提交于 2021-02-10 09:09:26
问题 When trying to run my ASP.NET MVC application locally, everything works fine. But once I've deployed it Azure, it keeps giving me the error: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. So I connected to the remote database using the Package Manager Console in Visual Studio and ran the Update-Database command. This gave me the same error. When I look at the database inside the SQL Server Management Studio, it looks

Add-Migration without parameterless DbContext and DbContextFactory constructor

我是研究僧i 提交于 2021-02-08 14:16:12
问题 My application has no parameterless constructor at my DbContext implementation and I don't like to provide a parameterless constructor to a IDbContextFactory<> implementation. The reason is I want to keep control where the DbContext points to. That's why all my constructors will ask for the ConnectionStringProvider. public class MyDbContext : DbContext { internal MyDbContext(IConnectionStringProvider provider) : base(provider.ConnectionString) {} } and public class MyContextFactory :