entity-framework-4

Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

纵然是瞬间 提交于 2019-12-23 04:48:00
问题 This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD). Thanks all. 回答1: Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex. I tried to implement a testing repository which was also a disaster. Trying to

How can I permanently fix the “EdmFunctionAttribute is obsolete” warning, which occurs after upgrading to EF6?

家住魔仙堡 提交于 2019-12-23 04:47:39
问题 I am getting the warning "EdmFunctionAttribute is obsolete" after I have upgraded a database first project from EF4 to EF 6.1.3: 'System.Data.Entity.Core.Objects.DataClasses.EdmFunctionAttribute' is obsolete: 'This attribute has been replaced by System.Data.Entity.DbFunctionAttribute.' C:\{myProjectPath}\DataContextEntityObjects.cs The attribute is used in various places like [EdmFunction("DataContext", "Split")] public IQueryable<Split_Result> Split(global::System.String rowData, global:

Error comes as a {“Invalid object name 'dbo.TableName'.”}

。_饼干妹妹 提交于 2019-12-23 04:45:50
问题 I'm using Entity Framework and MVC3, I have used Model First approch... I have used Company as a Base class and I have inherited the Lead Class from it. When I run the application its gives an error... This is Base Class using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } This is Lead Class (Child) using System; using System.Collections.Generic; namespace CRMEntities { public partial class Lead : Company {

Many to many checkbox and mvc

醉酒当歌 提交于 2019-12-23 04:03:29
问题 I'm using Entity Framework 4 and my model relationships are automatically generated from the lookup table. My models consist of Request and Building . A request can have many buildings, and a building can be associated with many requests. I've found a few posts on how DropDownFor automatically selects an item based on model relationships. But the HtmlHelper CheckBoxFor wants an expression that returns bool. My models don't have a bool indicating checked because it is based on the relationship

Entity Framework runs through all records (60,000!) when updating property for one

笑着哭i 提交于 2019-12-23 03:22:55
问题 I am attempting to set the value of a single property for a POCO object, and it's looking like Entity is doing a retrieve of every record in the database table from which the POCO object was originally retrieved. Here's the code: public void DeleteFile(int fileid) { var context = GetContext(myTrans, false); FILE pocofile = (from f in context.FILES.All() where f.File_Id == fileId select f).FirstOrDefault(); // the following line causes a retrieve of 60,000 records pocofile.State_Id = Global

How do I avoid a circular reference while serializing Entity Framework class

我怕爱的太早我们不能终老 提交于 2019-12-23 02:58:06
问题 I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return a JSON object from a controller action. This object is referenced by other objects, which obviously return the reference. I thus receive the following circular reference error: Server Error in '/' Application. A circular reference was detected while serializing an object of type 'Application.Models.ReferenceObject'. Description: An unhandled exception occurred during the execution of the current web request. Please

Generic repository implementation with EF

喜欢而已 提交于 2019-12-23 02:41:23
问题 For a simple repository public interface ISimpleRepository<T> { IApplicationState AppState { get; set; } void Add(T instance); void Delete(T instance); void Delete(Guid rowGuid); IQueryable<T> GetAll(); T Load(Guid rowGuid); void SaveChanges(); void Update(T instance); } my implementation of the Load() method for specific repository for class Product might look like this: public Product Load(Guid rowid) { return (from c in _ctx.Products where c.id == rowid select c).FirstOrDefault(); } Now

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

点点圈 提交于 2019-12-23 01:05:16
问题 How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider. I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (could do that, but it's overkill for the tiny project I'm working on). Is there built-in support in EF 4.0 for this that I'm missing or do I just need to go the

How to use Entity Framework 4.0 with Xml or in-memory Storage (non-SQL)

我只是一个虾纸丫 提交于 2019-12-23 01:04:41
问题 How do I specify Xml or just in-memory storge for Entity Framework models? The connection string requires a provider (usually a SQL provider string). But it won't let me omit the provider. I realize I could completely throw away the designer generated objects and go pure POCO, but then I'd have to implement my own serialization layer (could do that, but it's overkill for the tiny project I'm working on). Is there built-in support in EF 4.0 for this that I'm missing or do I just need to go the

How To Count Associated Entities using Where In Entity Framework

你离开我真会死。 提交于 2019-12-23 00:53:19
问题 I have this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Count() }).ToList(); But I need something like this: var queryResult = (from post in posts select new { post, post.Author, post.Tags, post.Categories, Count = post.Comments.Where(x=>x.IsPublic).Count() }).ToList(); But post.Comments is a ICollection 回答1: How about using Enumerable.Cast<T>() like this ? var queryResult = (from post in posts select new { post,