entity-framework-4

Entity Objects Validation and Business Rules Validation

Hi, I am developing application having business objects created from EF 4.0. The application is layered with Data Layer having repository of classes. Above that is a business layer where business processes are mapped as per the requirements. Business layer is calling data layer. Business objects have complex associations. One scenario:...

problem with take n rows and skip m rows entity framework

Hi, Im computing data from database (~130 000 000 rows). Because of big amount of rows I select 1 mln compute them save results then select another 1 mln and so on. I use select .. orderby .. skip m... take n...ToList() because I want to have this objects in memory. When I skip 1 mln then 2 mln then 3 mln ... then lets say 6 mln its...

EF Accessing Parent Navigation Properties from the Child

I have a EF Model constructed like the following WorkOrderHeaders Which has a FK into these parent properties (Many to One relationships) WOPriorities WOStatusTypes WOPersonnel Also has these Child collections which are Linked to its PK (One to Many Relationships) WOFieldUpdates WODetails The One to many collections load correc...

Entity Framework 4.0, Can't find connection name

I am trying to run a unit test with N-unit in a project. The project has the .edmx file in it, so it's not a multi-project problem that I see a lot of people. I kept all the defaults from what was auto generated by the Tool. My Web.config file appears to have the connection string in the <connectionStrings>: <connectionStrings> <add nam...

date difference in EF4

i need to get a difference of two dates ,one date from a table and one the current date, and the difference should be less than 9 0days. i need to use this as filter in where clause of the linq i tried doing this var list = from p in context.persons where ((p.CreateDT).Subtract(DateTime.Now).Days < 90) select p; i...

Simple Repository Pattern Question: How to query across multiple repositories efficiently?

If you return IList(T) from your repository ... How could you efficiently create SQL queries when you join the data together? Is it REQUIRED to expose IQueryable / IEnumerable data structures for those methods? This to me is bad. Or Am I missing some basic concept? Right now I have a repository methods like: IList<T> Get( Expressi...

Entity Framework 4: Repository method T Add(T entity) returns T: Can that actually happen (without SaveChanges)?

If you have an interface for a repository that includes T Add( T entity); The Repository wouldn't include a Save() or SaveChanges(). If you were to return "entity" with: return _dc.Entities.Where( n => n.ID == entity.ID).Single(); I wouldn't expect this to hit the database and auto-generate identity values (auto-incrementing). Tw...

Update existing EntityCollection in Entity Framework

I try to work with link to entity, and i want to work directly with my entity in my application. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Calandar.Business.Manager.Data; namespace Calandar.Business.Models.Args { public class SaveExpertArgs { public ExpertEntity Expert {...

How do you tell if an EF4 entity is new or an existing record?

In my application I have an entity which is being used essentially as a complex many to many between my User and Project entities. I am trying to determine how to figure out if my service layer needs to add the entity to the context or attach the entity (for updating an existing entity) and I am at a loss of how. This is easy to determ...

How to connect Controller to Service layer to Repository layer

Lets say I have the following entities that map to database tables (every matching property name can be considered a PK/FK relationship): public class Person { public int PersonID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Employee { public int EmployeeID { get; set; ...

Entity Framework 4 error: An entity object cannot be referenced by multiple instances of IEntityChangeTracker

I am using EF4 for the first time and have adopted a strategy of a UnitofWork (DataContext) per View. However, I am having issues and seek advice. I have a window that displays a list of workstations, when I click the edit button I have another window that displays the selected workstation for edit. The list view and the edit view use ...

Include,EF, ASP.NET and dropdownlist

I have a problem with include in EF, ASP.NET and dropdownlist. with the asp.net page : <asp:EntityDataSource ID="ds" runat="server" ConnectionString="name=CoreEntities" DefaultContainerName="CoreEntities" EnableFlattening="False" EntitySetName="Articles" Include="TraductionTitre"> </asp:EntityDataSource> <asp:DropDownList ID="Dr...

Entity Framework 4.0 with POCO classes - Repository pattern?

Hi all, i'm writing an asp.net mvc 2 web application with Entity Framework 4.0. I have the views that should display items, views that are for login, etc. Should i structure the project with a repository pattern? If yes, how? Should i create an interface for basics methods like Add, Update, Delete, etc and another class that use the repo...

Generating Entity Framework based on Views: Nullable types

Some of the properties in a class generated by EF are nullable, and some arent. My first instinct was that this should be driven by Nullable property returned by sp_help MyView. But that doesn't seem to be the case. Some of my types that are returned as Nullable by sp_help get generated as Nullable , while others, get generated as ju...

EF4 to datagrid with a combo box as a column in winforms

i have list of entities and i need to bind it to a datagrid...one of the properties in the list is a collection and i need to bind that to an combo box within a datagrid..i am new to windows forms... var list = (from p in db.persons select new person{p.firstname,p.lastname,p.phonenumbers}).tolist() i need phone numbers b...

Entity Designer Database Generation Power Pack: DROP CONSTRAINT is not in the T-SQL script generated

The T-SQL script generated by the Power Pack includes the statement that DROPS the table. But it does not script the dropping of FK constraints on that table. Thus the DROP statement fails. ...

Can't insert data to with EF with Master-detail relationship

Suppose I have 2 tables: Person(pid, ....) //Pid is identify colum as primary key Student(pid, Student_No,...) //pid is foreign key from Person, pid is a primary key too. Then use EF to generate entity model. THen try to insert new data with following code: Person person = new Person() { FirstName = "FirstName", LastN...

Entity Framework Code First CTP4 Default Column Values?

I have been looking into Code First with Entity Framework CTP4 and you can use the ModelBuilder to build up your table columns. Is there a way to set the default value for a column in the database using the ModelBuilder or some other mechanism? Thank You! ...

How do you convert numeric types in the mapping from a stored procedure to a complex type in Entity Framework 4?

We have two stored procedures in Microsoft SQL Server that return data that is conceptually of the same type. One returns an ID as SCOPE_TDENTITY() (a numeric), while the other returns 0 (an int32). We have a complex type with a property ID. If this property is a nullable decimal, we receive the following error when enumerating the resul...

How to pass a C# Select () extension delegate or expression to a Repository?

Everyone projects once in a while: var c = dc.Products.Select( p => new {p.id, p.name}); // results in c having properties of .id and .name What if I want to refactor that in to a method. How would I pass the Select parameter? var c = myFunction( p => new {p.id, p.name}); Product myFunction( ??? myLambda) { var c = dc.Product...