entity-framework-4

How should I remove all elements in a DbSet?

白昼怎懂夜的黑 提交于 2019-12-28 05:05:11
问题 What's the best way to remove all elements in a System.Data.Entity.DbSet, with Entity Framework 4.3? 回答1: dbContext.Database.ExecuteSqlCommand("delete from MyTable"); (No kidding.) The problem is that EF doesn't support any batch commands and the only way to delete all entities in a set using no direct DML would be: foreach (var entity in dbContext.MyEntities) dbContext.MyEntities.Remove(entity); dbContext.SaveChanges(); Or maybe a litte bit cheaper to avoid loading full entities: foreach

Why re-initiate the DbContext when using the Entity Framework?

北慕城南 提交于 2019-12-27 19:13:06
问题 I don't know if there is a better way to use the DbContext because it is not recommended to set is as static when working with WCF . So we are creating it each time we want to access the database. Knowing all the advantages of using Entity Framework, some become useless since we are recreating the DbContext each time; and more may cause overhead since the process of creating big entity models is to be considered. What is your opinion? 回答1: Managing Lifetime You're correct that a single static

Why re-initiate the DbContext when using the Entity Framework?

☆樱花仙子☆ 提交于 2019-12-27 19:12:59
问题 I don't know if there is a better way to use the DbContext because it is not recommended to set is as static when working with WCF . So we are creating it each time we want to access the database. Knowing all the advantages of using Entity Framework, some become useless since we are recreating the DbContext each time; and more may cause overhead since the process of creating big entity models is to be considered. What is your opinion? 回答1: Managing Lifetime You're correct that a single static

error when inserting into table having instead of trigger from entity data framework

扶醉桌前 提交于 2019-12-27 17:42:08
问题 I'm using entity framework 4 , on inserting a new record using entity framework in a table that have instead of insert trigger while the table has an identity column , the instead of trigger is used to modify one of the inserted value according to certain logic ,Entity framework raises exception "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries". Can

ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)

☆樱花仙子☆ 提交于 2019-12-27 11:54:39
问题 I am about to start implementing the data access infrastructure of a project that was architected with an approach to DDD ( it's my first attempt on DDD, so be gentle ;-) ). I will be using Entity Framework. Until now, I was looking into the method teached by Julie Lerman on her great book, Programming Entity Framework, where ADO.NET POCO Entity Generator is used, with some changes to the T4 templates and some more custom code. Today I started reading articles on EF4.1 and the ADO.NET

ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)

风流意气都作罢 提交于 2019-12-27 11:54:18
问题 I am about to start implementing the data access infrastructure of a project that was architected with an approach to DDD ( it's my first attempt on DDD, so be gentle ;-) ). I will be using Entity Framework. Until now, I was looking into the method teached by Julie Lerman on her great book, Programming Entity Framework, where ADO.NET POCO Entity Generator is used, with some changes to the T4 templates and some more custom code. Today I started reading articles on EF4.1 and the ADO.NET

Better way to query a page of data and get total count in entity framework 4.1?

折月煮酒 提交于 2019-12-27 11:54:13
问题 Currently when I need to run a query that will be used w/ paging I do it something like this: //Setup query (Typically much more complex) var q = ctx.People.Where(p=>p.Name.StartsWith("A")); //Get total result count prior to sorting int total = q.Count(); //Apply sort to query q = q.OrderBy(p => p.Name); q.Select(p => new PersonResult { Name = p.Name }.Skip(skipRows).Take(pageSize).ToArray(); This works, but I wondered if it is possible to improve this to be more efficient while still using

How to receive dynamically added values from view to controller in ASP.NET MVC?

情到浓时终转凉″ 提交于 2019-12-25 18:28:22
问题 I am learning some concepts in asp.net mvc. I am using entity framework and visual studio 2013 community edition. I am creating a demo app for learning. I have created model according to this link. The models are as follows. Below is course model. The course has department as foreign key. A department can have many courses. using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ManyItemsDemo2.Models { public class Course { public int CourseID { get; set

Relationships fixup in EntityFramework vs NHibernate

情到浓时终转凉″ 提交于 2019-12-25 12:05:31
问题 I have been experimenting with Entity Framework 4.4, NHibernate 3.3.1.4000 and SQL Server and I have noticed a difference when it comes to fixing up the relationships when you commit your changes, and I was wondering what is the best practice or if I'm doing something wrong. Here's what I tested. I have a classic Parent linked to n Children. I have 2 parents in the database with 20 children each. I load both parents, and I take the first child of the first parent and assign that child the

Relationships fixup in EntityFramework vs NHibernate

删除回忆录丶 提交于 2019-12-25 12:05:04
问题 I have been experimenting with Entity Framework 4.4, NHibernate 3.3.1.4000 and SQL Server and I have noticed a difference when it comes to fixing up the relationships when you commit your changes, and I was wondering what is the best practice or if I'm doing something wrong. Here's what I tested. I have a classic Parent linked to n Children. I have 2 parents in the database with 20 children each. I load both parents, and I take the first child of the first parent and assign that child the