entity-framework

Questions regarding Entity Framework + DDD

I'm having a difficult time finding straight forward examples of using EF in a DDD style pattern. This is also my first time employing DDD and have a few questions regarding solution layout and how to employ some of the DDD patterns. 1) Most of the examples I've seen regarding using the Repository pattern w/ EF just show specialized Mod...

Entity Framework: Changing the values of a table

Hi there, I have a table called say Table1 which has a column that is a primary key in another table. I want to change this value so I try Table1.OtherTableWithID.ID = Myvalue But i get the error "The property 'ID' is part of the object's key information and cannot be modified. " So how can i modify this value seeing that I cannot ac...

Naming them entities to make sense

Hello I was noticing that the designer for the edmx is giving the entities and classes strange names, all in plural etc, what should be the correct naming for it? like it is now is like: Customers (entity) CustomersSet (setname) Cusomters (navigation property) shall it be: Customer (entity) Customers (setname) Customer (navigation p...

Entity Framework - How to handle table relationships?

I have developed a fairly small asp.net MVC application using the repository pattern and Linq to Sql. I would now like to access and update the same data using the Entity Framework, however I am having trouble understanding if my syntax is correct for table relationships in the Entity Framework. Say I am retrieving a row of data for a ...

Entity Framework - only get specific columns

Can I make my EF objects retrieve only specific columns in the sql executed? If I am executing the below code to retrieve objects, is there something I can do to only get certain columns if wanted? public IEnumerable<T> GetBy(Expression<Func<T, bool>> exp) { return _ctx.CreateQuery<T>(typeof(T).Name).Where<T>(exp); } This would g...

How can I use the EntityModelSchemaGenerator to generate less then my entire model?

We have a big (and growing!) database. We're trying to not have to build the models by hand, and we found this EdmGen2 which is supposed to build our EDMX entity models for us. Since we have such a big database we'd like to not have all of our tables in the same Model. We got it all to work, but the generated model has all of our t...

Stored procedure search using entity framework

Hi everyone. I want to implement a search logic that I have seen and use. It works like this: There is stored procedure that is loaded in entity framework and it is used as a method in C#, it takes parameters in order to perform search. That method is returning list of views (DB View). The views in list have just some of the properti...

EF Query With Conditinal Include

I have two tables: a WorkItem table, and a WorkItemNote table. How do I return a WorkItem and all of the WorkItemNotes that meet a certain criteria? I think this should be simple, almost like a conditional "Include", right? ...

How to test business logic (Doman Model Rules) while using ADO.net entity framework?

I am trying to test that the business rule of not allowing to share the same space with a user twice. Below is the method being tested. The line having the issue is marked below. public void ShareSpace(string spaceToShare,string emailToShareIt) { SharedSpace shareSpace = new SharedSpace(); shareSpace.InvitationCode = Guid.NewGuid()...

Handling SaveChanges exceptions in a loop

Hi, In the Entity Framework, there are a few conditions which are handled at the database level, and passed back up to the EF as exceptions on a Context.SaveChanges(). If you are carrying out creation of new entities in a loop, you can handle the exception via the standard 'Try Catch' block, but how do you clear the problematic entity ...

Get duplicate key exception when deleting and then re-adding child rows with Entity Framework

I'm using the Entity Framework to model a simple parent child relationship between a document and it's pages. The following code is supposed to (in this order): make a few property updates to the document delete any of the document's existing pages insert a new list of pages passed into the method. The new pages do have the same key...

How to create an Entity Data Model for inherited generic types?

I have no clue how i can get an existing object structure based on the following classes (simplified) into a database using Entity Framework (EF is a constraint, i have to use it). public abstract class WahWahProperty { public string Name { get; set; } public abstract Type PropertyType { get; } } // ---------------- public class W...

Can't insert entries of a many-to-many relationship in Entity Framework in a specific order

Hello, I have a many-to-many relationship between 2 entities in Entity Framework, like here . So, Employees and Projects. At one point, I would like to insert some Projects to a Employees entity in a specific order. By conserving the order I would like to know which was the first preference of the Employees for a Projects entity. The th...

Iterate through data returned from var to get names and values of columns

I am using Linq to Entities in a method and returning specific columns of data from the method. I don't know what type I'll be returning so I rigged it to return a List. If someone knows a better way than the way I rigged it, PLEASE let me know. See the code below. After returning this data, I then need to iterate through the colum...

Entity Framework - inserting new entity via objectcontext does not use existing entity properties

I have an insert method on my repository like so: public T Insert(T entity) { _ctx.AddObject(EntityName, entity); _ctx.SaveChanges(); return entity; } If I execute the below code, the values assigned to my entity do not propagate to the SQL that is executed. Category c = new Category(); c.Name = CLEARANCE; c = categoryMa...

Problem with related entity on asp.net MVC create form using entity framework

Hi There I am building a very simple asp.net MVC file upload form. Currently I have a problem creating the new database object that stores info on said file. The code for the action method looks as follows: [Authorize(Roles = "Admin")] public ActionResult AddFile(Guid? id) { var org = organisationRepository.GetOrganisa...

Is ADO.NET Entity framework database schema update possible ?

Hi All I'm working on proof of concept application like crm and i need your some advice. My application's data layer completely dynamic and run onto EF 3.5. When the user update the entity, change relation or add new column to the database, first i'm planning make for these with custom classes. After I rebuild my database model layer wi...

Entity key of a view as navigation property

I have a table CREATE TABLE Tasks (   ID INT IDENTITY(1,1) NOT NULL CONSTRAINT PRIMARY KEY PkTasks,   ...other fields... ) and a view CREATE VIEW VTaskInfo AS SELECT   T.ID IDTask,   ...other fields... FROM   Tasks T How can I create navigation property connecting 'Task' and 'VTaskoInfo' entities? Usually defining navigation pr...

Incorporating a Windows Mobile, a Silverlight and a Web project under a common DAL (Ria Services)

I am in the beginning of my thesis, and I have to implement a solution about aggregating reports, obtained by a Windows Mobile application, to a central storage. Then, the available data are going to be presented through an Entity Framework model, using RIA services as a data access layer, for the Silverlight project. Can I utilize the R...

Why I can’t find any benefit of caching LINQ to Entity query?

Please look at my sourcecode. public class EntityQuery { public static Func<AdventureWork2008Container, IQueryable<SalesPerson>> selectQuery = CompiledQuery.Compile ( (AdventureWork2008Container aw) => ( from s in aw.SalesPerson join e in aw.Employee on s.BusinessEntityID equals e.Business...