entity-framework-4

Can I easily evaluate many IQueryables in a single database call using Entity Framework?

喜欢而已 提交于 2020-01-05 07:04:40
问题 Suppose I have a collection (of arbitrary size) of IQueryable<MyEntity> (all for the same MyEntity type). Each individual query has successfully been dynamically built to encapsulate various pieces of business logic into a form that can be evaluated in a single database trip. Is there any way I can now have all these IQueryable s executed in a single round-trip to the database? For example (simplified; my actual queries are more complex!), if I had ObjectContext context = ...; var myQueries =

Entity Framework 4: Is there a way to mark an entity “insert-only” (without using stored procedures)

橙三吉。 提交于 2020-01-05 07:00:11
问题 We are using the v4 Entity Framework as part of a new version of an application that includes some significant accounting functions (payment processing, cash balancing, bad check handling, etc.) In all of our previous applications, we have instituted a policy (which I'm told is extremely common in banking/accounting level applications) that there is at least one table, containing the incoming "audit trail" for all money, that can only be written to with new data. In other words, new

ASP.NET C# Entity Framework - How to update Foreign Key properly?

人盡茶涼 提交于 2020-01-05 04:57:27
问题 I'M quite new to this EF but I think I'M making progress. Anyway, it appears I do NOT know how to Update an object that is RELATED by a Foreign Key. My DbRelation is: And I'm trying to UPDATE the one members LANGUAGEID and here is the Context I invoke: public class ManagerBase { private static NoxonEntities _entities = null; public NoxonEntities Entities { get { if (_entities == null) _entities = new NoxonEntities(); return _entities; } } } There are many things I have tried. Here is one: 1)

Delete related elements in 1:N relation and not only inserts null in the foreign key

白昼怎懂夜的黑 提交于 2020-01-05 03:34:52
问题 I have the following class public class ObjectA{ private List<ObjectB> list; } ObjectA and ObjectB are in 1:N relation. I want to delete some of ObjectB instances and I use: while (objectA.list.Any()) objectA.list.Remove(objectA.list.First()); List is of the relation table - List<ObjectAobjectB> In the Database I have defined therelation as a nullable foreign key otherwise I get The operation failed: The relationship could not be changed because one or more of the foreign-key properties is

LINQ - Summing numbers stored as string

自作多情 提交于 2020-01-05 02:54:10
问题 I have the following data: PK OrderNumber USERDEFFIELD 1 0001 10 2 0001 25 3 0002 20 4 0002 22 5 0002 NULL 6 0003 ABC123 The UserDefField column is of VARCHAR type in the database. Using LINQ, how can I get the SUM(UserDefField) per order? NULL and non-numeric values for UserDefField are to be considered as zero. The result I'm trying to get: OrderNumber TotalQty 0001 35 0002 42 0003 0 If UserDefField is strictly nullable numeric field I know I would do this inside a foreach loop:

The method Distinct is not supported

眉间皱痕 提交于 2020-01-04 12:57:12
问题 I am using Linq to Entities and am getting this error The method Distinct is not supported On this line of code var typeIds = _context.AttributeValues.Select(av => av.AttributeTypeId).Distinct(); Why is this? 回答1: A solution is to define a WCF Data Service using (server-side) the QueryByCube method provided by my product AdaptiveLINQ (www.adaptivelinq.com). This method transforms a projection (expressed by the select operator) in an aggregation . You have just to define a cube with one

How to prevent EF4 from dynamically loading all assemblies

两盒软妹~` 提交于 2020-01-04 07:00:28
问题 We use ClickOnce with dynamic assembly loading. I recently added an EF4 model to a "Model" project within the solution. The application must not use the app.config file for it's connection string, so I create the ObjectContext using an EntityConnection. The application logic works perfectly, however, when you create an instance of the ObjectContext when the application is deployed using ClickOnce, EF4 tries to dynamically load all of the associated assemblies to find the metadata. This forces

EF4.1 DbSet vs. EF4 ObjectContext and Unit Testing

独自空忆成欢 提交于 2020-01-04 05:21:19
问题 I currently have a project I've started with EF4, and am going back and adding in unit testing after the fact. I am using the EF4 POCO T4 templates with my model (database) first context. I am using generic repositories for my DAC logic, and unit of work pattern for persistence. However, I'm running into some issues understanding how to mock up the ObjectContext/ObjectSet. I looked at using the FakeObjectSet<T> sample from this article, but it still leaves a few things out, such as auto

EF4.1 DbSet vs. EF4 ObjectContext and Unit Testing

让人想犯罪 __ 提交于 2020-01-04 05:21:14
问题 I currently have a project I've started with EF4, and am going back and adding in unit testing after the fact. I am using the EF4 POCO T4 templates with my model (database) first context. I am using generic repositories for my DAC logic, and unit of work pattern for persistence. However, I'm running into some issues understanding how to mock up the ObjectContext/ObjectSet. I looked at using the FakeObjectSet<T> sample from this article, but it still leaves a few things out, such as auto

Entity Framework Update - The context is not currently tracking the entity

狂风中的少年 提交于 2020-01-04 04:12:07
问题 I am trying to update an entity but I am getting the following error: The context is not currently tracking the entity. My DB table consists of the following fields: fixturedate, leagueID (FK), Team A (FK), Team B (FK). My code is as follows: public void UpdateFixture(Fixture validFixture) { Fixture fixture = new Fixture(); fixture = entities.Fixtures.Where(f => f.fixtureId == validFixture.fixtureId).FirstOrDefault(); League league = new League(); league.LeagueId = validFixture.leagueId;