entity-framework

dynamic Linq queries with Entity Framework

I am aware of few efforts in constructing Linq queries dynamically, such as this, and this. None seem to be ideal as I would like to avoid putting expressions in a string, and omitting a where if it is not needed. My main concern is that the query is optimized for the database, and dynamically omits unnecessary clauses whenever possi...

An error occurred while executing the command definition. See the inner exception for details.

Hello, In my mvc asp.net application, I am getting error in edit function : in given code public ActionResult Edit(int id) { var res = (from r in objeEntities.DocumentationsSet.Include("DocStatus") where r.textid == id select r) .First(); } I am getting this exception: Source : System.Data.En...

Under what circumstances are RIA services navigation properties loaded?

We have a Silverlight 4 client connecting to RIA services. It's based on the standard "Business Application" Silverlight application in VS 2010. The objects we send to the client over RIA services are EF 4 entities that are POCO objects generated from our edmx by T4. Our RIA service is a LinqToEntitiesDomainService<> of our linq reposito...

Entity relationship not reading correctly from database

I have an entity relationship setup in my mvc2 application such that each user has one role and each role can have many users. Like so: Roles Users -------- --------- RoleID-- UserID \ Name --> RoleID So a pretty basic many to one relationship enforced in the database and reflected in my entity relati...

Update Model from Database breaks when there is a View in my Model

One of my Entity Framework Models contains a MS-SQL View. The View is called User and contains various properties for users. When I right click on the model and select Update Model from Database, I get the following error: "An exception of type 'System.InvalidOperationException' occurred while attempting to update from the database. The...

Navigational properties lazily loaded even when ObjectContext.ContextOptions.LazyLoadingEnabled = false

I commented out the line of code that enables lazy loading from all the ctor overloads for my ObjectContext class, yet when I iterate over a navigational property, the iteration is successful. Why? Here's the relevant bits of code. public MyExpensesEntities() : base("name=MyExpensesEntities", "MyExpensesEntities")...

Can I implement foreign keys in Entity Framework 4 at the entity layer?

I have a sizable legacy MS SQL database where foreign key relationships were never implemented. Is it possible to implement "logical" foreign keys between entities in Entity Framework 4 without there being actual foreign key relationships present in the database? ...

generic class constraints: 2 types

i want to create a generic class that would accept T. T is an object coming from Entity Framework representing a Table, or a View of that table. properties on both would be the same. I would like to create a generic class, that will accept the table or view, and construct a linq query based on the properties. so i would need to d...

ASP.NET MVC - How to build custom viewmodels in C# to pass a data set to a strongly typed View?

Hi, I'm new to ASP.NET, C# and the MVC framework but have managed to build a site that works pretty well. Now I am trying to create a reporting section for the site to display a table of information on all users and just can't get my head around creating custom model classes for the joined table data. I have seen lots of examples with o...

Entity Framework, mapping Views to Tables

Hi, I have a basic view that returns the same columns as a table (give or take 1 field) in my DAL code, i am returning a list of MyTableObject, however in some cases, i will call the view to return the same data, but from different sources. List<MyTableObject> tableObjects = new List<MyTableObject>(); if (case1) tableObjects = ent...

Callbacks on entity on created/updated

I would like to know when entities in a certain database table are either created or updated. The application is essentially a CMS, and I need to know when changes are made to the content so that I can reindex them for searches. I know that the autogenerated LINQ to EF class has overridable methods for when certain fields change, but I...

How To Properly Unit-Test CRUD Operations on a Repository?

Hi Guys, Realize this may sound like a broad question - so let me clarify. I have a Repository exposed via an interface, with two concrete implementations - a MockRepository and a EntityFrameworkRepository. Now, i have a Unit-Test project for which all tests can be run against either repository, via flicking over a line in [TestInitial...

Adding two entities with FKs pointing to each other

I have two tables in my application. The first one, Sections, stores content for a specific section of an online publication. This contains (among other things) the section title and a field CurrentRevisionId (FK). A second table, Revisions, stores different revisions of that content. It has PK RevisionId field (the FK above, used to...

Entity Framework 1 - audit fields, many to many relationships and table per type inheritance

I am trying to come up with a reasonable EF1 entity model that maps to our SQL Server database schema and have hit a couple of issues related to a requirement that all tables in our database have fields for holding the last user of our application (not database user) to update the record and a timestamp of the last update. Let's call the...

ASP.NET Entity Framework: LINQ2SQL or Stored Procedures ?

Hi, I'm wondering about if there is a difference (in performance) when I use: User usr = (from u in Adapter.User where u.Login == login select u).FirstOrDefault(); or User usr = Adapter.getUserByLogin(login); //stored procedure ? ...

Entity Framework: table without primary key

Hello, i have an existing DB with which i would like to build a new app using EF4.0 Some tables have not primary keys defined, so that when i create a new Entity Data Model i get the following message: "The table/view TABLE_NAME does not have a primary key defined and no valid primary key could be inferred. This table/view has been excl...

Adding "second level object" with Entity Framework (C#)

Hi everybody, I'm trying to add an object: Person (id, firstName, lastName) and another object : Details(id, personId, phoneNumber, address). Of course, the "id" column in Person and Details is auto incremented. And the "personId" foreign Key is mandatory in Details. I'm using Entity Framework. I created some basic functions ...

When to use Entity Framework Pre Generated Views

I have read a fair amount about pre-generated views in EF but not sure which scenarios you wouldn't use it. My understanding is it simply requires a little set-up in your project and that is the only hit. So you will therefore get a performance improvement on first access of queries, essentially for free. If that is the case why would y...

EntityFramework Casting issues

I am building my query using PredicateBuilder from LinqKit. it is great and does exactly what i am looking for. To make my code more reusable (tables and views) i created a generic predicate builder class: public class LocalPredicateBuilder<T> where T : IResort ... var predicate = PredicateBuilder.True<T>( which exposes BuildPre...

Object Must Implement IConvertible LINQ to Entities query containing grouping

Hi. I have an ASP.NET MVC application in which i am using entity model for connecting to MySQl database Here I am joining 2 tables and then applying group by on one of the fields. Then fetching the result from GroupBy result. Everything is working fine on development machine but getting next error: Object Must Implement IConvertible...