entity-framework

How do you determine subtype of an entity using Inheritance with Entity Framework 4?

I am just starting to use the Entity Framework 4 for the first time ever. So far I am liking it but I am a bit confused on how to correctly do inheritance. I am doing a model-first approach, and I have my Person entity with two subtype entities, Employee and Client. EF is correctly using the table per type approach, however I can't ...

Compile error when calling ToList() when accessing many to many with Linq To Entities

I can't figure out what I am doing wrong. I have the following method: public IList<WObject> GetRelationshipMembers(int relId) { var members = from r in _container.ObjectRelationships where r.Id == relId select r.WObjects; return members.ToList<WObject>(); } Thi...

Entity Framework, ArgumentNullException

Hi! I have database with simple structure: markimaster(id, name), modelemaster(id, marka_id), typymaster(id, model_id) I defined relationships between tables and fetch data with this code: ObjectQuery<markimaster> markiQuery = context.markimaster.Include("modelemaster.typymaster"); bindingSourceMarki.DataSource = markiQuery; ...

asp.net mvc equivalent of rails callback before_save

Hi i'm looking for a asp.net mvc callback for elaborate data before save a model. In rails there is before_save. Thanks ...

Is the Entity Framework 4 "Unit of Work" pattern the way to go for generic repositories?

I am looking into creating an Entity Framework 4 generic repository for a new ASP.NET MVC project i am working on. I have been looking at various tutorials and they all seem to use the Unit of Work pattern ... From what i have been reading, EF is using this already within the ObjectContext and you are simply extending this to make your ...

Call function in query in Entity framework 3.5

Hello All: I am trying to run following query in entity framework 3.5 var test = from e in customers where IsValid(e) select e; Here IsValid function takes current customer and validate against some conditions and returns false or true. But when I am trying to run the query it is giving error "LINQ Method cannot be translated into a s...

Merge Function In Entity FrameWork?

when i use NHibernate i can find Merg function in session which do that : * if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance * if there is no persistent instance currently associated with the session, try to load it from the ...

Using Entity Framework as a Web Part's Data Source in Sharepoint 2010

I have a very simple web part. I have a single grid view, which I am populating using linq to entities (or at least that's what I want to do). The Entity Data Model .edmx file is located in the same project as the web part, and everything looks to be in working order. When I debug the project, it blows up on the entity model construct...

Which is more flexible in regards to database changes, EF 4 or Linq to SQL

Reading about both Linq to SQL and Entity Framework I have developed the impression that EF is more suitable for apps that get data from multiple data sources. But as I am reading about MVC2 models I see an example where EF is more loosely coupled with your data model. If I have to add or remove some columns from a table then what is i...

Is Entity Framework more mockable than Linq2Sql?

I've found that Linq2Sql doesn't (Rhino) mock well, as the interfaces I need aren't there. Does EF generate code that's more mockable? NOTE: I'm not mocking, yet, without interfaces, the next reader of this question may not have my bias. EDIT: VS2008 / 3.5 for now. ...

Can't submit new object to WCF DataService because of Primary Key constraint

I've got a SQL database that uses Guid's for PK's and upon insert, it generates a NewId(). I have an EF data context setup pointing to that database with the primary keys setup with the Entity key:true, Setter:private and StoreGeneratedPattern:Identity because I want the DB to manage the keys and not have code set the PK property. I h...

Dynamic Linq Library Guid exceptions

I am having a problem with the Dynamic Linq Library. I get a the following error "ParserException was unhandled by user code ')" or ','". I have a Dicitionary and I want to create a query based on this dictionary. So I loop through my dictionary and append to a string builder "PersonId = (GUID FROM DICTIONARY). I think the problem is wer...

How to start with entity framework and service oriented architecture?

At work I need to create a new web application, that will connect to an MySql Database. (So far I only have expercience with Linq-To-Sql classes and MSSQL servers.) My superior tells me to use the entity framework (he probably refers to Linq-To-Entity) and provide everything as a service based architecture. Unfortunately nobody at work ...

Deep copy objects from different namespaces

Hi all, I have the following situation: I have class User with the follwing properies : public class User { string user name ; List <Contact> contacts ; List <BookMark> book marks; . . . } I have the same class in a different namespace , with some different properties . BWT , it's the same situation of it's classes (Contact) an...

Authentication Problem in Silverlight - Cannot connect to SQL Server

Hi All, At the moment, when I try to register a user using the default Business Template in Silverlight, I am getting an error. Basically I am following a tutorial found on Channel 9 on how to build a business app with Silverlight. "An error has occurred while establishing a connection to the server. (provider: Named Pipes Provider, ...

Entity Framework - SaveChanges with GUID as EntityKey

I have a SQL Server 2008 database table that uses uniqueidentifier as a primary key. On inserts, the key is generated on the database side using the newid() function. This works fine with ADO.NET. But when I set up this table as an entity in an Entity Framework 4 model, there's a problem. I am able to query the entity just fine, but whe...

LINQ entity query performance

Hi all, I have a silly question. I would like to know if there is performance deference in these two quries: var cObject = from cust in entities.Customer where cust.id == cid select cust; and var cObject = entities.Customer.First( c=> c.id == cid); My query return only one record as I am querying with the prima...

VS 2010 and Entity Framework: accessing SQL Server 2000 databases

Consider a Visual Studio 2010 project whose requirement is to model the data using Entity Framework. The datasource is a SQL Server 2000 database. The first step is creating a new ADO.NET Entity Data Model item. The Entity Data Model Wizard prompts for a Data Connection. When creating a new Connection, you will need to use a provide...

How do I control the DisplayForModel method in ASP.NET MVC 2?

If I use DisplayForModel in a strongly-typed ASP.NET MVC 2 View with an EntityObject model, then unwanted field labels are displayed: EntityState EntityKey How can I control the output to hide these? ...

ThreadPool & Object lifetime

Hi, In an asp.net web application, there is a thread pool which is used to call a method. This method, uses an instance of EF ObjectContext to perform its operation. I am using Unity Framework which resolves an ObjectContext using the per-thread-lifetime manager. Does this guarantee that at the end of the method operation, the thread...