linq-to-entities

LINQ to Entities: Method cannot be translated into a store expression.

I saw this code work with LINQ to SQL but when I use Entity Framework, it throws this error: LINQ to Entities does not recognize the method 'System.Linq.IQueryable'1[MyProject.Models.CommunityFeatures] GetCommunityFeatures()' method, and this method cannot be translated into a store expression. The repository code is this: public ...

Get the first record of a group in LINQ to Entities ?

I am trying to group by an CarId field , and then within each group, I want to sort on a DateTimeStamp field descending. The desired data would be for each Car give me the latest DateTimeStamp and only that 1 in the group. I can get to this point, but having problems taking the top 1 off of the group and ordering the group by DateTimeS...

Working with SQL data via entity or LINQ?

Possible Duplicates: Entity Framework vs LINQ to SQL Dump Linq-To-Sql now that Entity Framework 4.0 has been released? What is faster way or better? Using LINQ to SQL or Entity ? ...

C# LINQ subquery (On entities)

Hi all, I am trying to use LINQ to query a list of objects wherever appropriate. Currently I am stuck on the syntax of a nested query which I hope you can help me with. Classes: public class FooType { public int Id { get; set; } public IList<Foo> Foos { get; set; } } public class Foo { public int FooTypeId { get; set; ...

UTC to local time using Linq to Entities

Hi all I need to translate a field from UTC to local time in a LINQ to Entities query. But it does not recognize the method 'System.DateTime ToLocalTime' that I was intended to use. My query was that way: Select requests for which doesn't exist any other request in the same day in local not yet resolved. Having into account that Inco...

Advanced queries in linq to entities or stored procedures

Hi all, I'm currently building an application using entity framework. Normally I would use a stored procedure to get specific data from my database but now i'm experimenting with Entity Framework. Now i'm facing a small challenge. I have an incident log table with a primary key, an incident id, and some data fields. I need to get all ...

Multiple Left Join LINQ-to-entities

I have 3 tables: Dealerships ------------ ID, Name, Website Locations ------------ ID, DealershipID, Address, Ect. Contacts ------------ ID, LocationID, Name, Ect. So the relationship shows that we have dealerships who have multiple locations (Example: Weed Chevrolet of PA, Weed Chevrolet of NJ) and then each location has its own co...

Filter view data based on user input

This is my first MVC app and I'm not sure how to use a parameter to filter the returned data. I'm using MVC2 and Visual Studio 2008. How do I filter view results based on user input? I want the user to be able to enter an ID number in a textbox and then click a button to get results filtered by the ID they entered. here is my Control...

Monthly report using Linq to Entities

I have a table named Rent that holds information about rent activities in a video library. I need to write a report that display rent activity per month from a given date. So far I have this query: from rent in hitechBuster.Rents where (rent.RentStart <= refDate && (rent.RentEnd == null || rent.RentEnd >= refDate)) || ...

How can I take a picture of my database Entity Framework model for people to reference?

My company has made an Entity Framework model of the database with all of the relationships mapped out and I'd like to take a screenshots of that with all of the FKs included in it. But I can't seem to figure out how to take a screenshot that includes all of that information. Any advice? The "Export as Image" feature of Entity Framework...

Entity Framework + conditionally appended Where() clauses

This is driving me nuts. What am I missing here. I'm using EF and if I have code like the following: using (LexiconEntities ctx = new LexiconEntities()) { var query = from w in ctx.Words select new WordEntryDataModel { Word = w.Anagram, NumOfAnagrams = w.NumAnagrams.Value, Length = w.Lengt...

Query Entity Framework object and child object with single query

I have two Entity Framework objects with a one-to-many relationship: widget(parent) and widgetNail(child) Widget has a text column: Title WidgetNail has a text column: Description I would like to build a query that will return a list of Widgets that match one of two criteria: A text string is found in the Widget title, or The same t...

[Linq to entities] How to convert anynoymous type ?

Hello, I try to convert an anonymous type to class but I don't. My code in ViewModel : <public List**<???>** PoolCondition { get; set; } Entities db = new Entities(); public SelectListViewModel() { string Lang = SessionManager.Language; var poolcondition = (from ddlv in db.Dr...

How to handle no results in LINQ?

in this example code public Company GetCompanyById(Decimal company_id) { IQueryable<Company> cmps = from c in db.Companies where c.active == true && c.company_id == company_id select c; return cmps.First(); } How should I handle...

entity framework - how can I implement this SQL in the abbreviated EF linq

Can anyone help out with what the C# code would be to implement this SQL as Entity Framework Linq in the abbreviated form? (e.g. where you have the "." notation such as xxx.where(... etc) SELECT PN.Name, Sum(U.Amount) FROM Usages as U, ProcessNames as PN WHERE PN.Id == U.ProcessNameId AND U.Datetime BETWEEN '2010-01-08' AND '2010-1...

LINQ to Entities 4: Query with calculation in where clause.

Hello. I have a table with a DateTime "TimeStamp" column and an int "TimeoutSeconds" column. I want to retrieve all records from this table where DateTime.Now - TimeStamp > TimeoutSeconds. In a stored proc this was a no brainer using GetDate(): select * from Schema.TableName mp where (GetDate() - mp.[Timestamp]) > mp.Timeout However, ...

linq to entities mapping

Hi, I got an error with mapping. I got a column in the database that has the data type image, because i need a byte[] image was the best option. So i changed that from string to byte[]. But now i get an error about mapping. I already changed the type string in the dropdownmenu properties of the column to 'byte'. That didn't help. How ...

Linq query question: Distinct based on object's property

I am aggregating multiple List's into one List and would like to make it distinct based on one of the properties of Foo (Foo.Prop1).. I do not have access to modify Foo's Equality comparer. Dictionary<string, List<Foo>> fooDictionary = new Dictionary<string, List<Foo>>(); List<Foo> foovals = (from e in fooDictionary ...

entity framework linq - which should I learn, method-based on query-based?

Just starting getting into Entity Framework and Linq for EF. I'm not sure which of the two query methods I should concentrate on, method-based or query-based? Is there an obvious choice as to which one is easier to use, for both simple and more complex queries, hence should be the one I concentrate on? Assuming I'm using VS2010 does m...

Entity Framework Foreign Key Table isn't saving changes made to its BindingSource

I have two tables: CREATE TABLE `Vehicles` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, ... Other columns PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 And: CREATE TABLE `VehicleOptions` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `VehicleID` int(10) unsigned NOT NULL, ...