entity-framework

Entity Framework Connection String Trouble

I am making a little library(DLL) to manage users and their roles/privileges. The plan is to be able to add this dll to an MVC project and be able to manipulate users/roles/etc. All the data resides in a SQL db. I am using entity framework for data access. So when I initialize a new RoleManager(this is the name of the main class in t...

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-...

Entity Framework How to query data in a Navigation property table

I have a the following setup m_handsets = From p In RL.App.TComEntities.tblTelephoneNumbers _ Where p.companyId = m_CompanyID _ Select p m_handsets = DirectCast(m_handsets, ObjectQuery(Of RL.TelephoneNumbers)).Include("tblCalls") where m_ha...

Entity Framework: To be or not to be?..

Hello everyone! I know I'm asking a question that probably has no definite answer, but please, I would like any and all opinions you might have. I used to be a big fan of LINQ2SQL because of it's ease of use. I used to hate creating stored procedures and would use Linq2Sql's lambda expressions instead. But main drawback i saw with L2S w...

How can I condense the following Linq query into one IQueryable

I have an EntityFramework model that has User entity that has an EntityCollection of Organisations. For a particular User I am trying to write a Linq Query to return the names of the organisations that the user belongs where that query will hit the db only once. My problem is that I cannot see how to write this query without having to ...

How to define and add a enum as type

I am working on custom data provider using ADO .NET Entity Framework. In the CreateMetaData function, I need to add primitive and complex properties in the ResourceType. I believe Enum should be added as the complex data type. If yes, how can I add this? Any pointer would be a great help. Thanks, Ram ...

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...

How do I expose non persisted properties using a WCF Data Service?

Hi all, I've created an entity model using Entity Framework 4, which I've exposed via a WCF Data Service. One of my entities needs to have properties defined that are not persisted to the database, but the Entity Model designer doesn't allow you to do this. To get round this I've defined all my objects as POCO objects, which allows you...

Transactions with EF

I have 2 questions : i) How can put this code in a transaction ? With ObjectContext in EF, I use ExecuteStoreQuery() method to start some stored procedure. I have a block of code like this : { foreach(...) { objectContext.ExecuteStoreQuery( @"INSERT MyProcedure (arg1, arg2) VALUES ({0}, {1}...

C# - Entity framework, duplicate unique exception?

Hello there, I'm trying to catch the exception throwen when I insert a already existing user with the given username into my database. As the title says then I'm using EF. The only exception thats throwen when I try to insert the user into to db is a "UpdateException" - How can I extract this exception to identify whether its a duplicate...

Adding A Custom Property To Entity Framework?

I am using the Entity Framework for the first time and want to know if the following is possible - I have generated my classes from the DB, and have one called Category. Obviously it has all my fields in the table (ID, CategoryName, SortOrder etc..) but I want to know if I can add a custom property which is not in the table, but is actu...

Entity Framework vs Linq to Entities vs Linq to SQL

Hi I read a lot articles about how to work with database in WPF .Net 4 application. As I understood, the main two technologies are: Linq to SQL (L2S) Entity Framework (EF) but sometimes I also can see mention of Linq to Entities (L2E) technology, but can't find clear explanation what difference between EF and L2E. So, my question i...

Custom properties in entity framework

Hi all, I'm wondering if this is feasible and how. I've an entity that is a simple 1 to 1 mapping against a database. I'd like to add a custom property to this entity that is the result of a stored procedure call. This SP returns a collection of the same entity (hierarchical data). Any ideas? Thanks in advance, Fabian ...

How Secure Is Entity Framework?

Just wondering if the entity framework is setup to handle things like SQL injection out the box? Every tutorial I have seen, video, book or blog post. No one mentions security and seems to pass in variables straight into the context with no checks etc... Just wondering what peoples thoughts were on this, and how do you handle this s...

Calling a UDF with Entity SQL but without a FROM clause?

Am trying to call a UDF which just takes a parameter and returns a scalar. The examples I've seen all use a From clause: http://blogs.microsoft.co.il/blogs/gilf/archive/2009/10/20/calling-user-defined-functions-udfs-in-entity-framework.aspx But I only want to call the UDF, I don't want to "join" it with any entities using a from clause...

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...

Entity Framework and Linq - Comparing DateTime

I have this code public List<CalendarData> GetCalendarData(DateTime day) { List<CalendarData> list = new List<CalendarData>(); using (dataContext = new VTCEntities()) { DateTime test = new DateTime(2010, 10, 20, 17, 45, 0); var data = from z in dataContext.ReservationsSet ...

entity framework with plugin datatypes

I want to build a system where user plugins can implement an interface for different data elements which are to be stored in a database. Now since I don't know the details of implementation until runtime, I can't create my database to encompass all derived types... but is it possible to perhaps: a) Manage entities only at the interface...

Related data in Entity Framework projection query not being tied together

My Database contains three tables: PermissionCategories, Permissions, and Users. There is a many to many relationship between Permissions and Users which is resolved by a UserPermissions table. Using Entity Framework projection I'm trying to get all the PermissionCategories and include (eager load) the permissions filtered by userId. M...

How to add child relationships when creating a new object in the Entity Framework

I have an entity framework project setup. It it I have four tables and three entities ("A", "B", & "C"). There is a 1:n relationship between A and B, and between A and C, and a n:n relationship between B and C. I use the following code to try to add a new "B" entity: A t = null; if (this.MyA == null) { t = new A() { ...