entity-framework

Count() in Linq to Entities does not generate SELECT COUNT SQL - generates exception

I'm performing a LINQ to Entities query (.Net 3.5 SP1) as follows: ... var blah = from obj in myEntities.Objects where... select obj; return blah.Count(); When I look at the resulting SQL in the SQL profiler, the query is calling a SELECT on a result set, not a Count. From a performance perspective, this is 10x slower than doing a ha...

SQL Server - Database 'Database' does not exist. Make sure that the name is entered correctly.

Hi, I'm trying to generate my database tables from my Entity Framework model, but I'm getting this error when I execute the generation query: Database 'Database' does not exist. Make sure that the name is entered correctly. I'm able to connect to the local server just fine. My connection string, which was generated by VS when I sele...

Can someone please clarify the key difference between Entity Framework and Typed Datasets?

I am comparing the EF and typed datasets for their usefulness. I was failing to see why you would use the EF over typed datasets if the EF is bound to SQL Server only. But is it true that the Linq statements in EF are evaluated late in the respect that if you did something like: db.Customers.where(c => c.Name == "John Smith") The EF w...

WPF DataGrid Parent Child Data

Hi All. I'm new to WPF/C#/NET but I have been learning by way of coding some small exercises. Anyway, I'm stuck. I have seached on here and google and can't find the answer or maybe more correctly can't find an answer I can make sense of. My problem is this... using the Entity Framework I have two tables. One for Employee details and ...

entity framework - naming of model with same types

Hi, I have 2 tables: Bikes and Wheels. Bike has 2 FKs to Wheels: Bike.FrontWheelID and Bike.BackWheelID. EF maps these onto Bike.Wheel and Bike.Wheel1, just using their type for name, which I would prefer to avoid. Is there a way to change this that would survive further regenerations of model from db schema? (some setting perhaps?) T...

WPF data binding using ADO.NET Entity Framework 4

Good Morning All, I'm having a small conceptual problem with ADO.NET EF4 (and perhaps ORM in general) and I was hoping someone could help fill in the gaps in my knowledge. In my example I have a normalised Database with two Tables: User & Company User // UserId(PK), CompanyId(FK), FirstName, LastName Company // CompanyId(PK), Company...

Manually update some items in FormView using EntityDataSource (ASP.NET)

Hi! What is the best way to manually update some items in a formview using Entity Framework? For example, I would like the user to select from a Checkbox list a few categories which the user will check the relavant ones. I would like to store those checked items as a comma seperated text in the database. If I am using SQL DataSource, ...

Entity Framework 4 ObjectContext Lifetime

Hi, Ive just started using EF4 with the repository pattern. Im having to call the dispose method after every use of context or wrap code arround in the using block. Can I use the ObjectContext without doing this in every method I write or is there a better way of handling this in the repository. Also I dont want to pass the ObjectConte...

Entity Framework Calculated Property problem

I've an Entity Framework model (v.1.0) that I'm trying to extends with a calculated property. I've created the partial class to extend the entity object "Offer" in this way: namespace MyModelNamespace { public partial class Offer { public bool MyProperty { get { // my stu...

Insert / Update with RIA services Compositional Attribute

I am creating a Silverlight 4 application with Entity Framework, RIA Services and MVVM-Light toolkit. The application deals with a complex object graph, that contains the following structure: Job 1->* Resources Job 1->* Workplans Workplan 1->* WorkplanItems Resource 1->* Assignment WorkplanItems 1->* Assignment I would like to...

Entity Framework CTP4 - Foreign key mappings across schemas don't work properly. Bug?

I'm having an issue with tables that have foreign keys to other tables in a different schema. For example, TableA in SchemaA has a foreign key to TableB in SchemaB. When CTP4 creates the database, instead of creating a foreign key from TA to TB, it creates a third table "TableA_TableB" with columns TableA_ID and TableB_ID as if it think...

Why does Entity Framework sometimes create relationships automatically and sometimes doesnt?

I have a simple schema similar to this: Customer CustomerId, FirstName, LastName, CreateDt CustomerFeedback CustomerFeedbackId, CustomerId, Feedback There is a foreign key relationship between the two. I create a LINQ to SQL model from this, and a relationship line is drawn between the two tables. I create an Enti...

How can i connect remote sql server by Entity Framework?

Hello everybody. I have no enough experience on database systems. I have to connect to remote sql server and process some queries on it. How can i connect remote server by Entity Framework ? ...

How do I call the Count method on an Entity Framework Context by using Reflection?

Hi, I'm trying to get count of records of each table by using the following code. But it doesn't work at all. GetMethod("Count") returns always null. I might do really stupid thing though, I don't know what to do. var list = new List<TableInfoContainer> { new TableInfoContainer{ObjectSetPropertyName="table1"}, new TableInfoCon...

Most efficient (for reads) way of modelling a One to Many relationship with EF4

This is a fairly simple question (or at least from the outset it should be). I am looking into efficient ways to model a One to Many relationship where the many is the same type. Example Say we have a Person Entity, and this person has 0 to many Sub-Persons, and the Sub-Persons have 0 or 1 Parent-Person. The answer should take into c...

What does the entity framework do with locking sql server

Hi, I'm not a real database expert, and i was wondering if you could tell me what kind of lock Sql server uses in combination with the entity framework in the following cases: I read 40 records from a table, update them in code and call SaveChanges to the context I read 1 record from a table, update it in code and call SaveChanges to ...

DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0

I am attempting to retrieve a list of objects from Entity Framework via WCF, but am receiving the following exception: There was an error while trying to serialize parameter http://tempuri.org/:GetAllResult. The InnerException message was 'Type 'System.Data.Entity.DynamicProxies.TestObject_240F2B681A782799F3A0C3AFBE4A67A7E86083C3CC4A393...

When making a model using the entity designer (VS2010) how can I maintain the data?

Because as I make small changes it regenerates the the entire DB and therefore removes the data.. I suppose I could manually maintain a script that I run that inserts the test data after I regenerate the schema. Or is there a better way to go about doing this? ...

Weird error in strongly-typed MVC2 view

The ViewUserControl below results in the following error at runtime: The Collection template was used with an object of type 'System.Data.Entity.DynamicProxies.Collection_1D9779ACB92AE24E3428C288EA7B1480A6477CF8861FB7582692E775613EFB3A', which does not implement System.IEnumerable. The error occures on this line: <%: Html.EditorFor(mode...

How do I get a non-null SCOPE_IDENTITY when using INSTEAD OF triggers in SQL Server 2008?

Possible Duplicate: Instead of trigger in SQL Server - looses SCOPE_IDENTITY? On SQL Server 2008, I have an INSTEAD OF trigger on a view. The SCOPE_IDENTITY() after the trigger is results in null. This causes problems with the libraries we're using. How can I control SCOPE_IDENTITY from within my trigger? This is absolutely n...