entity-framework

Entity Framework: Cancel a property change if no change in value

When setting a property on an entity object, it is saving the value to the database even if the value is exactly the same as it was before. Is there anyway to prevent this? Example: If I load a Movie object and the Title is "A", if I set the Title to "A" again and SaveChanges() I was hoping that I wouldn't see the UPDATE statement in ...

Entity Framework: Type based on a column value?

If a flag IsAdmin, cast as AdminUser otherwise cast as NormalUser. Was just curious about this but not sure how to do it. I do see that you can create a child object based on a table value and another table like: SiteUser is from the table Site_User AdminUser is from the table Site_User and Admin_User when Site_User.IsAdmin = true Ho...

Entity Framework - Detached Update issue

Ok, I am attempting to use this custom extension to perform an entity update. Right now it should update all properties and then all of its related ends (references). The problem is even though the entity with changes does have a related end with an entity key that is valid and correct (verified in the debugger its there). When the Relat...

Multiple joins to the same table with the Entity Framework

Hi, If I have a table with two foreign key fields to another table, I.E. Table: User Field: FK_PrimaryItem_ID Field: FK_SecondaryItem_ID Table: Item Field: ItemID When I'm using the entity framework, the generated objects become: User.Item and User.Item1 and I can't differentiate between the two of them. I can map back to the n...

Patterns or techniques for designing a flexible advanced search with Linq Expression Trees

I'm looking to add an "advanced search" capability to my ASP.NET/SQL Server 2005 application. Ideally, I'd like it to be table driven. For example, if my schema changes with the addition of a new column to a table that I want to search, I'd like to have the UI reflect the addition of the new column as a searchable field. I can envisio...

How to force ADO.NET Entity Framework to regenerate code?

I've run into a snag with a ADO.NET Entity Framework model and a ADO.NET Data Service that is making it available. The model and data service are compiling without any problems or warnings when they come out of source control. However when I run the service I get the following error: Unfortunately there are no server logs (that I am ...

Defining an Entity Framework 1:1 association

I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model. When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of ...

QueryObject Include Entity Framework

Hi, I have three tables: Scenarios, Components and Blocks. Blocks has a foreign key to ComponentId and Components has a foreign key to Scenarios. Blocks also has a foreign key (TreeStructureId) to another table TreeStructures. Now, why does this work: ObjectQuery<Blocks> blocks = edumatic3Entities.Blocks.Include("TreeStructures").Inc...

Entity Framework : Add Properties/Entities during runtime.

I want to use the entity framework. However I also have the requirement of allowing my users to define custom fields in our system. I would like to still use the entity framework and not use a a partial class with a hash table property. Below is the solution I was thinking of, however it is not simple so I would like to see if there is ...

How to place smaller tables in Domain & DB along with .NET entities

I have an important Object which have loads of properties. Now few of the properties could have multiple values for example consider, A Channel Object having one or mulitple producers (Now our client think that there could be only few producers like mostly 1 or 2 ). The same issue exist with almost 7 properties. Now i have two solution...

Server Explorer unavailable (VS2008Pro)

I recently had some problems with my VS 2008, and was recommended to reinstall. To make sure that the reinstall would solve my problems, i manually uninstalled everything that could have to do with VS and SQL Server (I had the 2008 Express edition installed). Now when I reinstall SQL Server and Visual Studio, the Server Explorer in VS i...

Examples of using F# to query Entity Framework

I'm looking all over Google to find an example or tutorial about using F# to query an Entity data source. Honestly I haven't found much. Have any of you had any luck ? ...

Enitity Framework with long-running object context

One of my chief annoyances with Linq to SQL in WinForms (and I daresay WPF) is the lack of support for long running datacontexts see here. The problem is that you can't get updates from the database, you only ever get the same old records until you throw the datacontext away. This is fine for a web app when the page is only alive for m...

Entity Framework AddTo function inconsistency?

Let me describe the behavior I get: Load a user from the database: this means the user is attached to the context Create a new Object C: C tempC = new C(); tempC.User = previously loaded user; Context.AddToCSet( tempC ); The last line throws an exception because the object was added to the context when the property user was set. bu...

EntiryFramework in WebApp: HowTo Store DSN

Hi, i'm using the entity framework in a asp.net 3.5 web application. What is best practice to store the database connection string in a secure (encrypted) way? (i'm using username/password to get to the database) (i have to delete the model very often, as the database designer in vs2008 does not update the foreign keys very good). ...

How To Save Navigation Properties in the Entity Framework

I'm trying to use the repository pattern to save an entity using the Entity Framework. I'm unclear on how to save the Navigation Properties (like Account below). Can anyone shed some light on this. Especially how one would set the AccountId from an MVC controller all the way through to the repository where it's saved. Thanks! --- Sa...

SQL produced by Entity Framework for string matching

Given this linq query against an EF data context: var customers = data.Customers.Where(c => c.EmailDomain.StartsWith(term)) You’d expect it to produce SQL like this, right? SELECT {cols} FROM Customers WHERE EmailDomain LIKE @term+’%’ Well, actually, it does something like this: SELECT {cols} FROM Customer WHERE ((CAST(CHARINDEX(@...

Is there any overhead with LINQ or the Entity Framework when getting large columns as part of an entity?

Let's say you have a table containing articles and you want want to display a list of them, excluding the actual article text. When you get a list of the article objects using LINQ or the Entity Framework, is there a LOT of overhead associated with getting that text column too? I assume that when you start enumerating the list, the art...

Best way to pass Entity Framework entity collections from the DAL to the Business Layer?

I have a DAL that makes calls to my Entity Framework Model. The calls return things like IOrderedQueryable and IQueryable objects. Should I convert them to something more universal in my DAL, such as List? But I assume that if I don't need to enumerate through the entire collection, this could be wasteful... So whats the best approac...

Why does an Entity Framework Connection require a metadata property?

I switched my DAL from using LINQ over to Entity Framework. Because my application connects to different databases depending on the current user, I need to dynamically create the DataContext at run time and pass in the appropriate connection string. However, when I tried to programatically create an Entity Framework connection using my...