entity-framework-4

Views and stored procedures - using both for DB security (Entity Framework 4)

I'm a bit new to database programming in general, and even newer to Entity Framework 4. I'm reading the O'Reilly Press book on the subject, and just want to be sure I understand what the author is saying about using views in conjunction with stored procedures for an added layer of security. She says: If you are reluctant to expose ...

EF 4 LINQ Expression load items based on related entity

Here is the expression x => x.stf_Category.CategoryID == categoryId x refers to an Product Entity that contains a Category. I am trying to load all Products that match given categoryId. In the db the Product table contains a Foreign Key reference to Category (via CategoryId). Question: I think I am doing it wrong. Is there somethi...

Entity Framework - Creating an Entity that matches Stored Procedure output

In Entity Framework 4, is there any easy way to create an Entity that matches the output of a stored procedure? I'm not talking about creating a complex type (which is easy), but creating an actual entity. The reason I want an entity rather than a complex type is that RIA doesn't seem to auto-generate an interface for complex types. ...

EF4 return new unique identifier from stored procedure

Hi, I am using EF4 and MVC 2. I am inserting a new record to the database, and I need it to return the new ID value. My stored procedure ends like this: SELECT SCOPE_IDENTITY() AS NewApplicationID; Here is my action method: public ActionResult CreateApplication(ApplicationViewModel applicationViewModel) { if (ModelState.IsValid...

Base Class in EntityFramework 4 POCOS

I Have Single Table Inheritance in EF4. when i use POCOs as it , it works will. but if i want to put pocos code in base class then inherit from it i get this Error : Blockquote Mapping and metadata information could not be found for EntityType 'ConsoleApplication2.Service'. this is my POCOs with parent (Solution ) and child ( s...

ASP.NET MVC save new record verse update existing record conventions

I'm working on my first ASP.NET MVC (beta for version 3) application (using EF4) and I'm struggling a bit with some of the conventions around saving a new record and updating an existing one. I am using the standard route mapping. When the user goes to the page /session/Evaluate they can enter a new record and save it. I have an action ...

Which functions does EF 4.0 support?

Sometimes I get an exception like this: "This method cannot be translated into a store expression". Is there any list what EF 4.0 supports and what doesn't? I have just googled, but nothing ;(. ...

Useful Silverlight class library with reference to .NET class library.

I'd like to develope simple set of controls to display many sort of data and be useful in normal silverlight application and can be used in ASP.NET MVC2 application. Right now i have no idea how to link those tehnologies, but this isn't my concern right now - i just heard it is possible and i'll find out how to do that... Right now i'd ...

How do I update a foreign key relationship in entity framework 4?

Hi, I have an object called Account, which has a reference to a timezone through a foreign-key relationship. On the Account-object I can see the TimeZone_Fk_Id as well as the reference to both Account.TimeZone and Account.TimeZoneReference. I am trying to update the foreign key relationship but I cannot figure out how. I have tried all...

How do I add a calculated column to my EF4 model?

Given a "User" table and a "Login" table in MS SQL 2008: CREATE TABLE [dbo].[User_User]( [UserID] [int] IDENTITY(1000,1) NOT NULL, [UserName] [varchar](63) NOT NULL, [UserPassword] [varchar](63) NOT NULL ) CREATE TABLE [dbo].[Util_Login]( [LoginID] [int] IDENTITY(1000,1) NOT NULL, [User_UserID] [int] NOT NULL, -- FK ...

Entity Framework 4.0 - Function Import - Stored procedure Resultset

I am using visual studio 2010 and with Entity Framework(EF). I am retriving data from database and binding into Gridview through Entity Model, using stored procedures. When I execute this Stored procedure in a SQL Query, its returns columns which is generated dynamically. ie., Execute (@PivotTableSQL). @PivotTableSQL contains dynamicall...

Generated property from db column in Entity Framework. Why an if condition is not there in setter of property in case of column allow NULL

If column allow does not allow NULL in db then a condition in setter of generated property in Entity Framework is if (_ColumnName != value) What is the use of this? Why this condition is missing in setter generated from columns which allow NULL? [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribut...

The specified LINQ expression contains references to queries that are associated with different contexts.

am getting this error on this code (this is an MVC project into which I am trying to integrate Entity Framework): List<string> consultantSchoolList = new List<string>(); // districts managed by consultant IQueryable<string> consultClients = rc.consultantDistrictsRepository.districtsForConsultant(userID); ...

SaveChanges() to update is not working

Hi, I am using MVC 2 and EF 4. I am trying to update my Application entity using my own stored procedure, but it is not updating. I checked out SQL Profiler and it is not even reaching the database. I also use an insert stored procedure and it works fine. Both stored procedures (insert and update) are mapped correctly. Does anyone ...

LinQ query has long duration because of View recalculation

Hello, I've created a View in the database that gives me a representation of an organisation structure AT THIS POINT IN TIME. Indeed, I use a getdate() in this view. I've imported the view in my edmx and wrote queries based on this view. Most queries join a table with the view and return a DTO. These queries work fine and are fast (200m...

Calling Stored Proc using EF4 with only some of the parameters

I'm currently working on a new system that uses already existing stored procedures that are used in another system. They contain lots of logic for validation etc. so I want to use them in my new system and call them from Entity Framework 4 using WCF RIA Services. Is there a way to only supply a certain number of params as some of the S...

Print Entity Framework Model for documentation purposes?

Does anyone know how to print out an Entity Model schema? What I would like is a list of my tables (entities), along with the columns, their data type and sizes. I would to print this out to use for "reference". (I'm old school, I still prefer having stuff like this printed, versus "reading" it on a monitor.) ...

asp.net MVC 2: in a create form, how to add new model relation entity with ajax request.

First of all , I use MVC 2 with Entity Framework 4. I Have 2 Entities. Customers and Emails There is a Relation 1 to many between Customer and Email. One customer ca have many Email. My question : In the Customer Creation page form, I have all the info related to the customer. ex: <%: Html.LabelFor(model = model.FirstName) %> <%: Ht...

Concurrent acess to EF4 entities (Parallel + EF4)

I'm currently working in a dispatcher service that processes thousands of messages delivered in different channels (email, private message, application message) using EF4 and WCF. To try to speed up message dispatching i'm trying to use Parallels: Parallel.ForEach(currentMessageList, m => { Processors.DispatcherWrapper.Dispatch(m, m.un...

Many to Many Relationships without Double Junction Tables, Entity Framework

I have the following setup (which works fine). Using CodeFirst (CTP4). A template has a list of influences, each influence gives a value to a trait. public class Template { public virtual int Id { get; set; } public virtual ICollection<Influence> Influences { get; set; } } public class Influence { public virtual int Id {...