entity-framework-4

Updating a list of foreign keys in EF4, using MVC 2 Repository Viewmodel Pattern.

Okay, I'm really struggling with how to update a list of foreign keys in MVC2/EF4. I have a one to many relationship between a Template object which can have many or no TemplateScenario objects. Essentially, I have an edit method in a controller that is trying to do this: // POST: /Modes/Edit/1 [HttpPost] public ActionR...

Entity Framework 4.0 - Versioning

Is this possible to implement with EF4.0? I have used NHibernate in the past and you can flag a timestamp column as a 'Version' column and it will enforce concurrency. Does this feature exist for EF4.0? If it does, are there any resources on how to set this up? If it does not exist, what alternatives do I have to handle 2 users editing ...

Using Entity Framework Code First CTP4 how to map an entity to multiple tables?

Using CTP4 and Code First, is it possible to map a single entity to two tables (using a 1-1 relationship between the two tables)? If so, how? MSDN: "How to: Define a Model with a Single Entity Mapped to Two Tables" http://msdn.microsoft.com/en-us/library/bb896233.aspx Related: http://stackoverflow.com/questions/3880237/mapping-data-...

Create a method that will return a Lambda Expression that will be use in a lambda WHERE clause. Got error 1025.

I use Framework Entity 4 in my project. I would like to create a function that will return an Expression Nothing seem to work. I get this Internal .Net Framework Data Provider error 1025. Here is my Expression Method public Expression<Func<SupplierTypeText, bool>> GetLmbLang() { return (p => p.LangID == 1); } I call...

Entity Framework 4 & Partial Class Inheritance

I havea simple EF Model with a Test entity and I want to make use of partial classes to add validation like this: namespace WebApp.Model { using WebApp.BusinessRules; using WebApp.BusinessRules.Rules; using Microsoft.Practices.EnterpriseLibrary.Validation.Validators; [HasSelfValidation] public partial class Test : B...

How do I get data from entities that inherit others in Entity Framework 4.0

new to EF - please bear with me. Due to the way the database was designed, in my model I have a User entity. The Contact entity inherits from the user entity, and the Profile entity inherits from the Contact entity. How can I get a list of Profiles, and, how do I create a Profile? I am able to get a list of Users no problem. Your he...

Any good books to pick up for a well-rounded reference to Entity Framework 4?

Hi guys. Been reading through Manning's NHibernate in Action book, and it has absolutely been terrific for laying out a good, solid, easy-to-digest (relatively) foundation on NHibernate. Question is, are there any comparable [reference] books for MS' Entity Framework 4 as well? I'm feeling mighty biased for NHibernate right now, and tha...

EF4: Difference between POCO , Self Tracking Entities , POCO Proxies

Hi, Can someone point me the difference between POCO , Self Tracking Entities , POCO Proxies? Actually, I am working Entity Framework 4.0 and POCO(Repository Pattern) and whenever I do some changes in the POCO and call ObjectContext.Savechanges then it reflects to the DB. My question is, How does the Context persist the change to t...

Entity Framework Code First & Search Criteria

So I have a model created in Entity Framework 4 using the CTP4 code first features. This is all working well together. I am attempting to add an advanced search feature to my application. This "advanced search" feature simply allows the users to enter multiple criteria to search by. For example: Advanced Product Search Name Star...

Getting the Schema from an EDMX file

I need to modify the T4 template POCO.tt to retrieve the database schema from the EDMX file. I can see the schema stored in an EntitySet tag in the XML. However I cannot find the schema anywhere when using an EntitySet object. Anyone know where I would find the database schema? Thanks ...

Detaching Entities in EF4 - losing object graph

As other questions have noted, when you detach and re-attach an object, any child objects are gone. I thought doing this: db.Properties.MergeOption = System.Data.Objects.MergeOption.OverwriteChanges; would cause subsequent reads to fully repopulate the object and graph when it was read in, but no such luck. Is there any way to get t...

Entity Framework 4.0 Scaling and Security

I want to use an ORM, and have been looking at EF 4. Is this platform scalable. I see a lot of stuff on the web, but everything looks very biased in one way or the other. Anyone know of benchmarks or non-subjective information. On that point, does EF prevent SQL injection or XSS. I know that it used parametrized queries, but is that eno...

Entity Framework -- How to set properties to special types

Hi All, I'm new to MVC and Entity Framework, so this may be a relatively simple answer, but I've tried searching around so far and no luck. I'm using the most recent versions of both tools to my knowledge (MVC 3 Beta and Entity Framework 4.0) I'm just trying to set up a quick example. Logically, I'm dealing with events -- in this case...

Creating a one-to-one mapping in Sql server 2008 and Entity Framework 4

I have two tables, Customer and CustomerConfiguration that should have a one-to-one mapping. What I did was make customerId the primary key (and identity) for Customer, and then created a customerId field in CustomerConfiguration that is unique and is mapped to the Customer.customerId. So this seems to give me what I need, and EF4 pick...

Get Last ID From The table [ Entity Framework ]

Could someone guide me on this. I am using EntityFramwork4 , I want to get the ID of the last row of a table. Could someone having experience using this tell me , how can i get the last id from a database table. ...

Control table names Entity Framework Generate Database from Model

I was working with entity framework in a database first style. Each time I wanted to update my edmx file I did just that, ran update model. The problem I now have is that I've lost my database (long boring story, it was on a disk that's been formatted and I don't have a backup). I thought I would be able to use the 'Generate Database fr...

Regenerate an EDM with the same name as the one deleted

I have a WinForms application. I created an EDM from my database and called it Foo. Then, I deleted the model. Now, when I try to regenerate the same EDM again from the same database, it doesn't allow me to name the newly generated model Foo. It says that the name Foo conflicts with a property in the application's settings. I poked aro...

Using .Include() when joining a view using Entity Framework

Im using an Indexed View which is an entity without any relations (relations to my table entities would be preferable but this seemed to be nearly impossible to achieve). This view consists of 4 FK's which together form the PK: PortalID CategoryID BranchID CompanyID Now im joining this view to select a set of companies like this: var...

Hide columns in a DataGridView

Let's say I have a table like so: Friend ------ Id int not null FriendName nvarchar(50) not null Phone nvarchar(50) null If I bind my DataGridView control in a Windows Forms application to an ObjectQuery<Friend>/ObjectSet<Friend>/IList<Friend> returned from an ObjectContext like so: MyFriendsGridView.DataSource = _context.Friends.ToL...

Linq to EF Search for a string that does not start with a Letter

I am using Linq to Entity Framework 4, what I'm trying to do is build a query that finds all supplier entities that do not start with a letter, typically these are numbers, e.g. "1st Choice" I thought this would be trivial and wrote this: var letters = Enumerable.Range('A', 26).Select(x => (char)x); var results = from supplier in All() ...