entity-framework-6

Navigation properties not loading properly

一曲冷凌霜 提交于 2019-12-04 03:55:31
My context looks like: public class ApplicationDbContext: IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { this.Configuration.LazyLoadingEnabled = true; } //DbSet properties } so, lazy loading is enabled. I have following class: public class Home { private ICollection<Slide> _slides; [Key] [Required] public string Name { get; set; } [ForeignKey("Header")] public int? HeaderID { get; set; } //Navigation properties public ICollection<Slide> Slides { get { return _slides ?? (_slides = new List<Slide>()); } set { _slides = value; } } public Content

Why does Azure Database perform better with transactions

南楼画角 提交于 2019-12-04 03:43:40
We decided to use a micro-orm against an Azure Database. As our business only needs "inserts" and "selects", we decided to suppress all code-managed SqlTransaction (no concurrency issues on data). Then, we noticed that our instance of Azure Database responded very slowly. The " rpc completed " event occured in delays that are hundreds times the time needed to run a simple sql statement. Next, we benchmarked our code with EF6 and we saw that the server responded very quickly. As EF6 implements a built-in transaction, we decided to restore the SqlTransaction (ReadCommited) on the micro-orm and

Entity framework update one column by increasing the current value by one without select

喜欢而已 提交于 2019-12-04 03:14:47
What I want to achieve is the simple sql query: UPDATE TABLE SET COLUMN = COLUMN + 1 Is there a way to make it happen without loading all records (thousands) to memory first and loop through each record to increment the column and then save it back? EDIT I tried raw sql and it worked. I have to decide the sql provider from the connection string and the database schema name from the connection context. After that, I will use the corresponding sql query to update the table. For SQL, it looks like UPDATE schemaname.TABLE SET COLUMN = COLUMN + 1 . for POSTGRESQL, I have to double quote schema name

Entity Framework 6 - Missing table with only primary keys referencing different tables

邮差的信 提交于 2019-12-04 02:50:33
问题 We are learning Entity Framework 6.1 (from NuGet) as we move away from Linq2Sql. We have a small handful of tables that associate two separate tables like shown below. EF6 Database First generation DB Diagram: Schema Overview: When in Visual studios, blank class library, doing a Database First EF6 EDMX file, the diagram only generates TableA and TableC -- the TableB does not get generated. Visual Studios View: You can see that only TableA and TableC are created. Technically TableB should have

Entity framework manually deleted tables cant be generated from EF migration

混江龙づ霸主 提交于 2019-12-04 02:44:13
I have created migration and created the database and the tables . For example the tables are A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E . Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run update-database . It gives the error that apart from the two tables . There already an object existing

does Visual Studio 2015 include .edmx support?

♀尐吖头ヾ 提交于 2019-12-04 02:30:46
Does Visual Studio 2015 include .edmx support? I have a project that includes an .edmx data model and double-clicking it in VS2015 just opens the XML editor. There's no DbContext generator option in the file->new dialog. During setup of VS2015, go to the advanced options and select Web or Database Development tools. Now the Installers install the EF tools (Designer + templates). If you have VS already installed, to the Programs & features in control panel and modify the currently installed VS2015. You have to select the Microsoft SQL Server Data Tools in the VS2015 setup to get this editor

Merging migration entries in Entity Framework

。_饼干妹妹 提交于 2019-12-04 02:20:15
I have an Entity Framework 6 CF project that has a few migrations already in place. The model is now stable and there is no need to keep the migration history that already exists. Is there a way to reset the model and merge all migration commands into the initial migration? As an example, the first migration adds a column while the second migration adds a unique, non-clustered index. I now want to see all these changes directly in OnModelCreating rather than in separate migrations. Migrations have both an Up and Down . You can always Re-Scaffold your application by tearing the migrations down

How to map table names and column name different from model in onmodelcreating method in Entity Framework -6?

走远了吗. 提交于 2019-12-04 02:15:58
I have my database with table names starting with "tbl" prefix and column names like "ua_id" which are understandable in context of project but problematic if used in a model i.e names should be readable or meaningful(not like indicative names defined in database). So I want to map them in my onmodelcreating method but I have no idea about it. I studied it in following blog: http://weblogs.asp.net/scottgu/entity-framework-4-code-first-custom-database-schema-mapping but this is for EF 4.1 and method doesn't work for EF 6.(mapsingletype method) I want to map my tables by columns to my model as I

EF 6 filtering child collections

我的未来我决定 提交于 2019-12-04 01:41:15
I'm trying to migrate old project from Linq2Sql to EF6 and I got following issue. This project is multilingual (i.e. all texts have more than 1 translation) and I have following db structure: What is the best way to get all ExampleEntity1 objects with all LocalizedContent records filtered by current language id? I can load all ExampleEntity1 objects with all LocalizedContent records using following code: dc.ExampleEntity1.Include(ee => ee.TextEntry.LocalizedContents); In Linq2Sql I can filter LocalizedContent records using loadOptions.AssociateWith but I can't find any solution for EF6. I saw

loading navigation properties with raw sql query

和自甴很熟 提交于 2019-12-04 01:17:30
问题 I have this SQL query: SELECT t.ServerId, t.Id, s.Name FROM MyTable as t JOIN Server s ON t.ServerId = S.Id I'm running it with: context.Database.SqlQuery<entity>("query_goes_here"); How can I configure EF so that it loads the Server property of my entity with the return data from the query? Based on the answer by @octavioccl, I ended up doing this: foreach(var result in results) { context.Attach(result); context.Entry(result).Reference(p => p.Server).Load(); } But I'm afraid this is making a