entity-framework-4

Entity Framework 4: How to code projection to a class type?

If I have a class like the following: public class Customer { public int id {get;set;} public string name {get;set;} public string line1 {get;set;} public string line2 {get;set;} public string line3 {get;set;} public string line4 {get;set;} } And I only want to select the ID and Name values, leaving the ...

DDD Architecture for ASP.NET MVC2 Project

I am trying to use Domain Driven Development (DDD) for my new ASP.NET MVC2 project with Entity Framework 4. After doing some research I came up with the following layer conventions with each layer in its own class project: MyCompany.Domain public class User { //Contains all the properties for the user entity } ...

Do i handle well database connections (Entity Framework)?

I think i am doing something wrong in here so i will paste here so you can put me to the right track: public MembershipCreateStatus CreateUser(string username, string password, string mail, bool autoemail, string fullname) { using (TemplateEntities ctx = new TemplateEntities()) { ...

Modify DomainService code?

How can one modify DomainService code without the custom code being overwritten? Is there a way to put the custom code in a seperate class file? Thanks. ...

Entity Framework 4 Repository returning IList: What C# code could limit which POCO fields populate?

If you populate a drop down list of possible values, you only want the database query to pull two fields, a value and text (like customer ID and Name). However, your Repository returns POCOs, namely the entire Customer record. I wouldn't think you should create a POCO for every single DDL list you need, so how does one specify to a rep...

EF4 does not commit Updates

Hi Sorry to ask such a general question: what can cause EF to insert records but not update ? I face a strange situation where i change an entity and when i call SaveChanges(), the changes are not committed in the DB. thanks Jon ...

Am i using correctly Unit of Work here? (Entityi Framework 4 POCO)

I found some examples of how to create unit of work with ef4, i haven't used di/ioc and i would like to keep things simple and this an example (90% inspired) and i think it's ok but since i am looking at a pattern to use from now on i would like to ask an opinion one last time. public interface IUnitOfWork { void Save(); } publ...

Is the activerecord pattern built into Entity Framework 4.0?

In the past I used Sub Sonic which has the activerecord pattern baked into the framework. With Sub Sonic it was very easy to find the "dirty" fields on an update. I now have a need to create an audit table in my application that utilizes Entity Framework 4. Is there a comparable feature in EF 4 that will give me the dirty fields? Thank...

Entity Framework 4 Abstract Model - How to Programatically Eager-Load Navigational Properties?

Hi Guys, I have an EF4 Model that is built with abstract entities/classes: Notice how State entity has a navigational property called Country. Note: I have lazy-loading disabled, so i must eager-load on demand. Now, if i have the following method: public Location FindSingle(int id) { return _repository.Find().WithId(id).SingleO...

Inherited C# Class Losing "Reference"

I have a partial class using an interface because I can’t inherit what was an original abstract class due to the other partial class being auto-generated from Entity Framework 4 and therefore already inheriting ObjectContext. I have the following for my partial class: namespace Model { using Microsoft.Practices.EnterpriseLibrary.Va...

ASP.NET MVC2 and EF4 - Creating checked checkboxes in an Edit view

I'm currently in the process of creating a shared Edit/Create view for my game review project and have hit a snag. Each game can be a title on a variety of platforms. I have this mapped as a many-to-many relationship in my EF4 model. For my view, I'd like to have a series of checkboxes with the names of each platform, and, for the Edi...

How can I avoiding casting yet pass in the correct type.

I am using Entity Framework v4. I am trying to implement some logic to Validate my entities before they are saved by overriding the SaveChanges method. I am also POCO for my entities. I get a list of modified and new entities by doing the following. var entities = (ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityStat...

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

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 (c...

Entity Framework 4 and Synonyms

Hello, If, in Database A, there exists a table named "MyTable" that actually comes from a synonym pointing to another database (B), can I create this table as an entity in an Entity Framework model that represents database A, since it actually resides in a different database? I'm curious if the situation with EF 4 has improved since th...

Exporting Entity Framework 4 Data Model to Entity Framework 3.5

Is there a way to export a EF 4.0 Data Model to EF 3.5? I looked around and found that we are not able to access EF 4.0 from a ASP.Net 3.5 project here: http://stackoverflow.com/questions/2876887/using-entity-framework-4-0-in-a-net-3-5-application Our project is the 1st to go to .Net 4.0 using Entity Framework and we (the team) were wo...

Modifying an Entity Framework Model at Run-Time

This is purely a conceptual and design idea related to EF4. The example/scenario is a large ERP or CRM type system where companies may need to add traditional "user defined fields" to capture additional data. I know that the EF has some capabilities to push out the model to a database at run-time but the question really is can you use ...

3 entities execute the same lambda predicate. How creating one lambda expression generic for these entities.

I Have 3 entities. Product LangID ProductName Category LangID CatName ProductType LangID TypeName As you can see, each of them has LangID Property. I Would like be able to create a generic repository that will contain only one function that will return an Func<T, bool> GetLmbLang() public interface IBaseRepository<T> where T : c...

Problem with UPDATE Operation On Entity Framework 4 (Pure POCOs)

Hi Guys, I have an Entity Framework 4.0 model implemented with pure POCO's (no code generation, no self-tracking entities, just plain old CLR objects). Now, here is some code i have in my UI to perform an UPDATE: [HttpPost] public ActionResult UpdatePerson(Person person) { repository.Attach(person); unitOfWork.Commit(); } Es...

Entity Framework: how to do correct "Include" on custom type

Suppose we have 2 types, mapped to a Database via EF 4. Schedule 1.....1 Visit Also, we have third custom view type public class ScheduleView { public Schedule Schedule { get; set; } public Visit Visit { get; set; } } So we can write the join query var query = Context.Schedule.Join(Context.Visit ,/*Schedule join key defin...

EF4 error: Unable to load the specified metadata resource

Hi, I have just deployed my ASP.NET MVC 2 application using EF 4 and I am getting the following error: Unable to load the specified metadata resource. On my local machine it runs fine with no errors. This error only comes now when I deployed to the server. I have my enity data model file in MyProject.EntityModel. I used the POCO e...