entity-framework

How to use Entity Framework to work with many-to-many relationships?

I have a SampleDB that contains 3 tables. Table Employees (EmployeeID, EmployeeName) Table Projects (ProjectID, ProjectName) Table ProjectResources (ProjectID, EmployeeID) The ProjectResources table is cross reference table that creates a many-to-many relationship between Employees and Projects. I would like to use LINQ to select all...

Is AutoMapper mapping EF relationships well?

I am using Entity Framework + AutoMapper to convert the EntityObjects to POCO. The relationships in EF use EntityCollection<T>. The relationships in POCO use ICollection<T>. Since EntityCollection<T> : ICollection<T>, i thought it would be super easy to cast. However, when AutoMapper tries to cast the EF EntityCollection<T> to POCO, it...

Proper place for db connection in SOAP web service (.net)

I have an asp.net web site and a database. The web site has a web service for storing feedback from my software. As far as I know, IIS will reuse the created object for sequential requests. This gives a reason to connect to the DB in web service's constructor, properly implement Dispose() method, and use the connection for serving each...

Update command not working in Dynamic Data Details view.

I have just create a very basic Dynamic Data web application using Entity Framework, and when I click the edit command from the GridView, to open a Details view, edit some fields, and click the Update link, nothing happens. My question is what could cause this update to do nothing and are there any tips for diagnosing it? MORE INFO ...

Can't do projections to Persistence Ignorance (POCO) class using EFPocoAdapter

Given a simple POCO class such as: public class User { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } } When I try a query with projection to itself like so: using (var context = new Context()) { var user = context.User.Select(u => new User { Id = u.Id }).FirstOrDefault(); } ... I ...

What are Navigation Properties in Entity Framework for?

Hi I see in my EF diagram alot of these navigation properties but not sure what they are really for. Like I see in lots of my tables I have aspnet_Users properties. What are these for? Do they help for joins? or what? Error 2 Error 3007: Problem in Mapping Fragments starting at lines 1201, 1423: Non-Primary-Key column(s) [Field2] are...

ADO.NET EF: Assign model to table without existing database

I've created an ADO.NET entity data model with Visual Studio and have to assign the properties to a matching table now. If I create the data model with an existing database, Visual Studio uses this database automatically to assign the properties. I have to start with a clear model because I don't have access to the database, the only thi...

What am I missing with my Entity Framework?

Hi I have asp.net membership and I use the built in Create user method since it is convenient now after this depending on the user I want to add 2 more fields to the aspnet_UserTable. In my aspnet_user Table I have like this // All Standard Fields that come with this table ClubID<nullable) ClubName <nullable) I have a table that re...

How to get a related object sorted with Entity Framework for ASP.NET MVC

Having two classes like Blog and Post, in Entity Framework (and LINQ-to-Entities), how can you get the blogs with the posts sorted by date. I was getting the blogs with the posts this way: from blog in db.BlogSet.Include("Posts") select blog and now I'm forced to do this: public class BlogAndPosts { public Blog Blog { get; set; }...

Adding & Updating Foreign key in Entity Framework v1

Hello, I'm using .NET 3.5 SP1. I created entity 'Category', based on table 'category_table' and 'MyUser', based on table 'App_User_table'. CREATE TABLE category_table ( catg_id int, catg_name varchar(50), catg_description varchar(250) ) CREATE TABLE App_User_table ( userid int, username varchar(50), fullname varchar(50), catg...

Entity Frmwk pb: search for 'added' entities in current context

I'm using guids as PK for my entities. As EF doesn't support the newid() SQL statement, I force a Guid.NewGuid() in my creation methods. Here is my problem : I've a table with a clustered unique constraint (2 strings, not PK). I'm running some code in the same EF context which perfoms operations and adds/links entities, etc. Is it pos...

Why is AutoMapper/EF adding a new item instead of a relationship?

I have this test in my test base: public void WorksWithAreaUsers() { using (new TransactionScope()) { //arrange var userBusiness = new UserBusiness(); var user = new User { Name = "TestUser###", Login = "domain\test-user###" }; userBusiness.Add(user); var...

Deleting an entity that has an un-loaded child entity

I need some clarification re cascade deletes in Entity Framework and despite searching for hours am no closer to a solution. In a nutshell, if I have an entity (MyObject) that has a 1->0..1 relationship with a child (MyObjectDetail) then I can't delete MyObject without an UpdateException complaining about constraints - but ONLY IF the ...

Ado .net data services in the same app

I have an application with an EDMX and an Ado .net data service in it. I would like to make a call from the same application (not an http call) to the ado .net data service and would like to use the url like syntax to query using a string of filters that have been built up programatically: public class AdventureWorksService : DataServic...

How do I do this in Entity Framework(multiple where's or Join)?

Hi I have 2 tables that have a relation ship to each other Table A has 1 to many relationship with table B so this make a navigation property into each. Now I need to check a value from Table A(userName) and I need to check a value from table B(ClubId). So in my mind it would be something like Join the tables together Where A.userN...

Entity Framework with lots (50K+) tables

I would like to use the Entity Framework against a database with well over 50,000 tables. I only want to create entities on a small portion of these tables (less than 10). When I go to add tables using the wizard or server explorer, Visual Studio seems to not be able to handle that large amount of tables. It appears as if the tree vie...

Entity Framework creating IQuerable of the most recent

Hi I have an Entity set that has Entities with a compound key containing ID (GUID) and CreatedAt (DateTime). This CreatedAt is when the entity was created. Each record represents each version of each entity such that muliple records can have the same ID. I want to create an IQuerable-returning method that I can re-use such that it will...

Problem while working with many-to-many relationships in Entity Framework

I create some items from a class X. I add them to de base, do SaveChanges and all this... The class Y has a relationship many-to-many with X. Using another Context, I create a Y instance, putting into the collection of X the elements I've created. I add Y to Y entity set, it is fine. When I do Context.SaveChanges(), I get: A value ...

Does a LINQ to Entities query eventually get translated into Entity SQL?

If I write a LINQ to Entities query does that get translated to a native query that the provider understands (i.e. SqlClient)? OR Does it get translated to Entity SQL that the Entity Framework then translates to a native query and passes to the provider? If it gets translated to Entity SQL where I would I be able to see the Entity SQ...

Asp.net membership Table: aspnet_UsersInRoles not showing up in Enity Framework designer

Hi I made an Entity database and it generated all the tables but it seems to have forgotten about the aspnet_usersinRoles table. I don't know why it would skip this one or how to add it. When in I look in the Model Browser through VS2008 I see the the aspnet_UsersInRoles table. ...