entity-framework-4

Entity, dealing with large number of records (> 35 mlns)

对着背影说爱祢 提交于 2019-12-06 05:10:50
问题 We have a rather large set of related tables with over 35 million related records each. I need to create a couple of WCF methods that would query the database with some parameters (data ranges, type codes, etc.) and return related results sets (from 10 to 10,000 records). The company is standardized on EF 4.0 but is open to 4.X. I might be able to make argument to migrate to 5.0 but it's less likely. What’s the best approach to deal with such a large number of records using Entity? Should I

How to handle an association table linking the same 2 tables

你说的曾经没有我的故事 提交于 2019-12-06 04:48:32
I am using Entity Framework 4.3 code first using an already existing database. There is a Users table that has the following columns: - UserID (int) - FirstName (string) - Surname (string) I have an association table called Impersonations . The Impersonations table is an association table between a user table and the same user table. A user can have a list of users. Here is the Impersonations table structure: - ImpersonateID (int primary key) - UserID (int FK to Users table's UserID column) - ImpersonatedUserID (int FK to Users table's UserID column) I have a User class with properties that I

How to extend Entity from EF?

假装没事ソ 提交于 2019-12-06 04:47:07
All entity created by EF is partial class. so it is extendable. Suppose I have entity Person like partial class Person{FirstName, LastName, .....} Then I want to add a compute property Name like: partial class Person{ [DataMember] public string Name { get { return String.Format("{0} {1}", this.FirstName, this.LastName); } } partial void OnFirstNameChanged() { //..... this.ReportPropertyChanged("Name"); } partial void OnLastNameChanged() { //..... this.ReportPropertyChanged("Name"); } //.... } Then for data upate operation I got following error: The property 'Name' does not have a valid entity

Entity Framework - Read Lock on Record

南笙酒味 提交于 2019-12-06 04:40:41
问题 I'm calling same database from different applications using Entity Framework. However, when one application is reading/updating a record, I do not want other applications to read that data. I tried with the following sample code; however, they are still able to read the record. Any suggestion OR different approaches will be highly appreciated! using (Entities context = new Entities(ConnectionString)) { DBTable entity; do { entity = context.DBTable .Where(item => item.IsLock == false)

EF4 CTP5 - LINQ Dynamic Query Library throws InvalidCastException

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:04:51
问题 With the upgrade to EF4 CTP5, the previously working (with CTP4) LINQ Dynamic Query Library throws the following exception Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery' to type 'System.Linq.IQueryable`1[KIT.TAM.Core.Entities.TravelAgent]'. on the return statement below: namespace System.Linq.Dynamic { public static class DynamicQueryable { public static IQueryable<T> Where<T>(this IQueryable<T> source, string predicate, params object[] values) { return (IQueryable

DbContext ChangeTracker: Id of Added Entity for Auditing

*爱你&永不变心* 提交于 2019-12-06 03:48:18
问题 I have something like this: public override int SaveChanges() { foreach (var changeLog in this.ChangeTracker.Entries() .Where(p => p.State == EntityState.Added || p.State == EntityState.Deleted || p.State == EntityState.Modified) .SelectMany(entity => AuditRecords(entity))) { this.ChangeLogs.Add(changeLog); } return base.SaveChanges(); } But, of course, audited change logs will not contain the primary key value of the entity when the EntityState is Added (until after SaveChanges). How can I

Entity Framework - update field value to current DB server time

ⅰ亾dé卋堺 提交于 2019-12-06 03:43:01
问题 I've pulling back an entity object from a database and I need to update the date to the DB server's date/time - usually you could accomplish this by setting it with the SQL getDate() function. How can I accomplish this in the following scenario: var client = context.client.Where(c=>c.clientID == 1).FirstOrDefault(); // the value needs to be the value of the server's current date, i.e, getDate()... not DateTime.Now client.someDate = <somevalue>; context.SaveChanges(); 回答1: Try inserting the

Explicit many to many join table in Entity Framework 4

二次信任 提交于 2019-12-06 03:32:07
问题 By default EF hides a many to many join table that does not contain additional data than the foreign keys to the joined tables. Is it possible to tell EF (and the designer) to explicitly create the join table and make it usable in code? Thanks 回答1: No EF designer will not add this entity for you. If you want junction table exposed you must manually delete created relation and add junction table's entity and two one-to-many FK relations. Here are related questions with step by step guide: How

Is there any way to create a LINQ query as a variable without having the data source (yet)?

筅森魡賤 提交于 2019-12-06 03:06:34
问题 Preamble: My core question is very similar to this one: How can I write a clean Repository without exposing IQueryable to the rest of my application? which has remained unanswered. I am hoping that if I approach the problem in a different way, and ask a slightly different question, I may get a result. I will repeat some of the content from this other question to avoid requiring readers to read it for context. Problem: I'm working with POCO entities, and Entity Framework 4. I am trying to

Entity Framework 4.1: Override IEnumerable<ValidationResult> Validate

拥有回忆 提交于 2019-12-06 02:23:42
问题 public abstract class Animal , IValidatableObject { public string Id {get;set;} public string Name {get;set;} public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if (this.Name == "animal") { yield return new ValidationResult("Invalid Name From base", new[] { "Name" }); } } } public class Dog: Animal, IValidatableObject { public string Owner {get;set;} public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { /* Here