linq-to-entities

How do you manage your ORM layer when database undergoes changes ?

I understand the reason behind not auto refreshing your .dbml (Linq2Sql), .edmx (Linq2Entities) or .hbm.xml (NHibernate). In each of these ORM solutions you need to update these files if you have changes in the database. Is there a way to refresh these files automatically if you are 100% sure that it wont break anything? I am reasonably...

How do you do full text search (FTS) with Linq to ADO.NET entity framework?

Now that SQL Server 2008 has full text search built in. I'm looking to use it to power my website's search. I'm also looking at using ADO.NET entity framework for my ORM but I was wondering how do you do full text search (FTS) with Linq to ADO.NET entity framework? Is there any support in ADO.NET entity framework or am I stuck using the...

LINQ to Entities how to return all records from the Parent table?

I am unable to select all the records from the parent table using Linq to Entities. This is a simple DB design (image below): Image Link This is the exact output I want using Linq to Entities or Linq to SQL (image below): Image Link When I use Linq to Entities or Linq To Sql I can only get the records from the child table that ha...

Linq to Entities How to return all records from Parent?

Employee table Employee_ID int Employee_Name varchar(50) Sales table: Sales_ID int Employee_ID int Sale_Amount money Standard SQL select Select * From Employee emp left outer join Sales s on s.Employee_ID = emp.Employee_ID Standard SQL Results (The exact results I want using Linq to Entites) ...

MVC + Entities Framework: Many to Many relationships

Hi folks Im new to MVC and EF. I have a basic app that lists info from a few (4) tables relating to some servers. One of the relationships is a many to many (Servers to Roles). I pass my ViewData to the View by making use of this in the controller: ViewData.Model = (from s in _db.Servers.Include("Locations").Include("OperatingSystems"...

Entity Linq - Retrieve record and only the first child record in a one to many relationship.

I have an entity called "Requests" which has a navigation called "StatusHistories" I need to retrieve all of the Requests where the last StatusHistory is "Open" StatusHistory has the fields StartDate (the highest one of these would be the last StatusHistory) Status (for this presume status contains the string "Open" or "Closed") Recor...

LINQ to Entities Searching text properties for multiple keywords

Hi guys, For a website I'm doing we're using LINQ to Entities. I have been charged with adding search functionality to the site. I'm trying to figure out the most elegant way to search for multiple keywords (user entered) on a single field in the database. Allow me to give an example. Table columns: Name, Description Example row: ...

linq to entities inheritance query problem.

I'm trying to perform a linq to entities query on a table that's inherited using Table per Type. The problem I'm having is that I can't get at the properties on the Inhertied table only the properties on the Base Table. var qry = from i in _DB.BaseTable where i is catalogueModel.InheritedTable // Field Doesn't Exist // && i.InheritedTa...

LINQ to Entities for subtracting 2 dates

I am trying to determine the number of days between 2 dates using LINQ with Entity Framework. It is telling me that it does not recognize Subtract on the System.TimeSpan class Here is my where portion of the LINQ query. where ((DateTime.Now.Subtract(vid.CreatedDate).TotalDays < maxAgeInDays)) Here is the error I receive in the VS.NET ...

linq to entities generated sql

I am having some problems with linq to entities in the ado.net entity framework. Basically what I'm doing is this: var results = (from c in companies where c.Name.StartsWith(letter) select c); and this gets translated to SQL as something like: WHERE (CAST(CHARINDEX(@p, [Extent1].[Name]) AS int)) = 1 which is fine but my table has...

E2L: How do you handle Foreign Keys that participate in multiple relationships?

I have a Database model like this FlowObject FlowObjectID (PK) Description Active ProcessObject FlowObjectID (PK, FK) HasSubmit DecisionObject FlowObjectID (PK, FK) YesFlowObjectID (FK) NoFlowObjectID (FK) YesCaption NoCaption When I try and use create my Entity model I get this warning in my project. Foreign Key constraint 'FK_Pro...

What type of object should I be binding to my WPF form in an n-tier app?

I am currently working on a small N-Tier application in C# which uses Linq-to-Entities (SQL Express 2005 for the DB) and WPF and I am wondering what type of data collection my business logic layer should be supplying to the user interface. Are there downsides (performance, validation etc) to binding form objects like datagridviews to an...

Loading relations in linq2entities automatically

When i have a relation between two entities in my model: [GroupMember] (*) ----- (1) [User] and tries to select items from this relation with LINQ: From entity in _user.GroupMember select entity I always get an empty result unless I load the relation first with following statement: _user.GroupMember.Load() Is there a way to avoid l...

What is the way to make a select on a nullable foreign key field in Entity Framework?

Hi, I have a category table which has a foreign key to it self by a nullable parentId field. In Entity-Framework when a relation is created, the entity is generated without any relation fields. I mean, in my example when I created a parentId-Id relation in Category table, the generated Category Entity will have an int typed Id property ...

How to move from Linq 2 SQL to Linq 2 Entities?

I'd like to start a reference for people who want to move from linq2sql to linq2entities and the ADO.net Entity Framework (in here called L2E). I don't want to discuss which of these two is better. I just want to create a list of differences between these two for people who want to transition from one to the other. The basic stuff is ea...

Entity framework getting around unsupported methods

ADO.NET EF does not support things like Math.Pow and Math.Log so I was wondering how I can get around this. I need to be able to use an ORDER BY on a calculated value using ADO.NET EF. ...

Mocking an Entity Framework model?

Is it possible to mock an EF model so that I can test code which uses the model classes without getting rid of LINQ to Entities code strewn throughout my project? Or will it be necessary to set up a test database for the model to hit instead? ...

ADO.Net Entity Framework across multiple databases

In Linq2Sql you can connect a data context to multiple databases by just adding the database name to the source. Is there a way to achieve this in Linq 2 Entities / ADO.net Entity Framework? Can the database name somewhere be added to the table name? I tried to change the 'Schema' from dbo to MyDatabase.dbo, but the EF encapsulates thi...

How to avoid MSDTC?

Maybe this is just a stupid idea, that's why I toss it in here: I am creating an application, using one database for base and current data (customers, articles, inventory, open invoices, ...) and one database per year for archive data (old invoices, inventory movement, ...). There is only one nasty little problem: MSDTC. Most transacti...

Create new LINQ to Entities Objects with associations

I'm trying to get my head around how to add new records to a table that have a foreign key to another table using LINQ to Entities. I'll try and explain: Say I have a simple database with two tables. For example lets call one LibraryItem and the other LibraryItemStatus. The LibaryItem has a foreign key to the LibraryItemStatus table ...