entity-framework

How to generate table from model in ADO.NET Entity Framework?

How is it possible to create an entity in the visual studio designer and generate a table from it? I find it much easier to generate my entities within VS than to create a table in SQL Server. Also, if I do generate an entity from table, is it possible to make changes to the entity and push them to the table? ...

Composite Foreign Key Question

I am trying to figure out if it is possible to create a foreign key in this way. First there are two parent tables in this scenario. Table 1 has a PK int and another int column. When combined the two are unique. Table 2 has a PK int and another int column. When combined the two are unique. The paired value between the two ints is how...

Mocking Entity Framework Context

I'm using the entity framework to access my database and I want to mock the database context inside my unit tests so that I can test my middle tier classes free of their dependency on real data. I know that I'm not the first to ask about this (Mocking an Entity Framework Model), but after some googling I have an instinct that it might be...

ADO.NET SQL Client Provider default database connection

Does the .NET SQL Client DataProvider always connect using the master database. I've noticed that when I connect to the database to execute an ADO.NET query and then look at the active connections in SQL Management studio, the SPID for the .NET SQL client provider always uses master DB The initial catalog in my connection string is tha...

Upgrading Enterprise Library (1.0) to LINQ or Entity framework

We are working on a C# windows project with enterprise library 1.0 that needs to be updated to either LINQ or Entity framework. (.NET 3.5) The application uses mainly SQL connections as stored procedures and XML files to store settings. What is the pros and cons with LINQ and Entity framework in this case? Are the rumors true that LI...

A beginners Entity Framework query to populate a WinForms ListView.

I've just started learning how to use the Entity Framework to write a very simple C# network monitoring program - this is a learning exercise to try and "drive home" what I've only read about to date. I'm also new to C# and LINQ (just to complicate things further.) I believe I have the data model suitably normalised but I may be wrong. ...

Return plain objects in entity framework for serialization

I have been trying out both Linq to Sql and EF in my ASP.NET MVC application. After switching to EF I realized my XML/JSON serialization output has extra cruft. XML: <Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <EntityKey> <EntitySetName>Persons</EntitySetName> <...

ADO Entity Framwork Diagram problems

Environment: Windows Vista x64 Visual Studio 2008 Pro Edition 9.0.30729.1 SP Microsoft .NET Framework Version 3.5 SP1 Problem: 1) Blank Entity Framework Diagrams can be opened but no tables can be dropped into the diagram from the Data Connections or 2) Entity Framework Diagrams can be populated with "generate from database" option bu...

Can I call a Stored Procedure from an EntityDataSource?

(ASP.net 3.5, C#, SQL Express 2008) I want to have a Web Form, where I can search for "Solutions" (my table) using a keyword entered by the user and after the result comes back and populates a GridView. I already have parts of this search via a stored procedure that is hooked up to my Entity Data Model. On this page I have an EntityDa...

Entity Framework: Should the EntityContainer name contain at least two words?

I am using entity framework, using (almost) hand-crafted csdl, ssdl, and msl files. I've noticed that object construction seems to fail if the name of the EntityContainer consists of a single word. For example, for the following two csdl files : <Schema Namespace="BestProduct" Alias="Self" xmlns="http://schemas.microsoft.com/ad...

LINQ to DataSets for MySQL Interop

I'm building an application that must support MSSQL and MySQL databases. To avoid duplication of stored procedures etc., I'm considering using the Data Access Application Block to retrieve broadly scoped, very general datasets from either database, and then use DB agnostic LINQ code for more specific data access. My other option is to ...

Entity Framework: Creating custom properties in Business Layer (object)

Using Entity Framework the DataLayer is created (DataLayer.dll) The DataLayer.dll contains the data-objects. I need to add some business logic to the class 'person'. Yes, i know, that I can use partial classes, to add business logic. But in this case (using partial classes) we need to implement it in DataLayer.dll! I need to uses the ...

Entity Framework and associations between string keys

Hi, I am new to Entity Framework, and ORM's for that mather. In the project that I'm involed in we have a legacy database, with all its keys as strings, case-insensitive. We are converting to MSSQL and want to use EF as ORM, but have run in to a problem. Here is an example that illustrates our problem: TableA has a primary string k...

Looking for a code sample or "template" for an EF Repository

I'm looking for a good Entity Framework repository code sample or template. ...

LINQ is able to filter on association, but returns 0 results when referenced directly

I am a little confused with a statement I am testing out. I am working with LINQ to Entities I have commented in the code below. It is the last Console.WriteLine which I do not understand. I appreciate anyones input on this using(Ecommerce.Data.Entities.EcommerceEntities ents = new Ecommerce.Data.Entities.EcommerceEntities()...

Problem with Dynamic Data and entity Framework

Hello, I'm trying to use Dynamic Data with a entity model that has Abstract class that are Derived by sub entities. Whenever i run the website i get this error: model.RegisterContext(typeof(QMSModel.QMSEntities), new ContextConfiguration() { ScaffoldAllTables = false });[KeyNotFoundException: The given key was not present in the dicti...

How do I get the entity framework to stop setting the rowversion field?

Im using the Entity Framework and I have a rowversion (timestamp) field on a table to use for concurrency. However, when updating the entity object, it keeps trying to set the rowversion column to null, and I get an error: The 'VerCol' property on 'LmpDemoRequest' could not be set to a 'null' value. You must set this property to a non-...

Entity Framework Exception: Index was outside of the bounds of the array."

OK, I am having and issue with Entity Framework. I have had it working, but have now added several more entities to the model, and now I am getting the above error. For debugging purposes, I have created a test form with a grid control to populate from my Projects entity collection. FYI, I am using GUID's for my primary keys. I only have...

Linq query to include a subtype

In my model I have Address as a base class and MailingAddress, Email, and Phone as subclasses of Address. A Person has an address so query to get a person who has an Oakland Mailing address would look like this: var peopleInOakland = from p in entities.DbObjectSet.OfType<Person>() from a in p.Addresses.OfTy...

EntityFramework Business Logic on EntitySetReference

I am trying to do something where if have a two classes (that i care about) one called Inquiries and the other is a foreign Key Table of InquiryStatus What my business logic I am trying to check if the Inquiry gets tied to a new InquiryStatus which would have InquiryStatus.bln_requiresValue then I need to have an Inquiry.Money Rig...