linq-to-entities

Entity-Framework eagerly-load first item of a nav-property

Is there a way to make this code excute in one query with Entity-Framework? Private Sub LoadFirstPhone(vendor As Vendor) If Not vendor.ContactReference.IsLoaded Then _ vendor.ContactReference.Load(MergeOption.AppendOnly) vendor.Contact.Phones.Load(MergeOption.AppendOnly) End Sub I want two things: I want to be able...

How to write this linq query to avoid too many query?

I have two table Company and Employee. And there relation is Company(one) - Employee(many). And I want to concatenate all the Employees' name to a string and output. I know I can write such a query : String names = ""; foreach(var emp in Company.Employee) { names += emp.name; } But If I use this mean, I would l...

What is the fastest way to convert all PK and FK GUID Columns and relationships to int?

I'm currently developing an ASP.NET MVC application with a ton of PK-FK relationships in the database. In the beginning of development, the team I WAS working with voted against my recommendation to use INTs for all PKs... they decided to use GUIDs. Long story long... the team has split ways, and now I have control to change things... ...

Does dynamic GroupBy work together with dynamic Where in dynamic LINQ ?

I use this dynamic LINQ library together with Linq-to-Entities. I build query and after that iterate it with foreach(object e in query){} query=db.Table1.Where("it.FieldA>10").Select("it.FieldB"); works. query=db.Table1.Where(e=>e.FieldA>10).GroupBy("it.FieldB", "it").Select("key") works. But query=db.Table1.Where("it.FieldA>10").Grou...

InnerException on saving data with linqToEntities

Hi everybody, I have a problem with LINQ to Entities. When I try to save data I obtain an error: Error error during the updating of items. for further information see InnerException. The stack is: An unexpected exception type was thrown Expected: System.ArgumentException but was: TAP2009.AuctionSite.Interfaces.UnavailableDb...

The method 'Skip' is only supported for sorted input in LINQ to Entities.

What could be causing this problem? public ActionResult Index(int page = 0) { const int pageSize = 3; var areas = repo.FindAllAreas(); var paginatedArea = new PaginatedList<Area>(areas, page, pageSize); return View(paginatedArea); } using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

Linq to Entities - Get First Image from products in categorie

Hi, i'm having some trouble in making this on right. I'm trying to get the first image from each product inside a specific categorie, but so far i get all fotos, repeating the product list: Dim Produtos = (From P In ProductsCtx.produto _ Join C In ProductsCtx.categoria On C.id Equals P.categoria_1.id _ ...

Querying Entity with LINQ using Dyanmic Field Name

I have created a dynamic search screen in ASP.NET MVC. I retrieved the field names from the entity through reflection so that I could allow the user to choose which fields they wanted to search on instead of displaying all fields in the view. When the search result is Posted back to the controller, I receive a FormCollection containing...

Trouble converting a bit of TSQL to LINQ to Entities

Sorry about the vague title, not sure what verbage I should be using. I have a query similar to this (re-worked to save space): SELECT * FROM Publishers p INNER JOIN Authors a ON p.AuthorID = a.AuthorID INNER JOIN Books b ON a.BookID = b.BookID WHERE p.PublisherName = 'Foo' ORDER BY b.PublicationD...

What does the "...parameterless constructors and initializers are supported..." error mean?

I'm getting this error: Only parameterless constructors and initializers are supported in LINQ to Entities. When trying to run this code (found this code here and made test database to play around with): XElement xml = new XElement("contacts", from c in db.Contacts orderby c.ContactId ...

Can I "undo" a LINQ to SQL update?

In LINQ-to-SQL if I update an object in the context but haven't called SubmitChanges, is there a way to "undo" or abandon that update so that the changes won't get submitted when I eventually call SubmitChanges? For example, if I've updated several objects and then decide I want to abandon the changes to one of them before submitting. P...

Linq to Entites has-many-through

Greetings - I could use some with creating a linq to entities statement that would include all my models. I have three models: Alumni, Logs and LogTypes. An Alumnus may have many Logs and Logs may have one LogType. If I want the alumnus with the logs I would say: Alumnus alumnus = _entities.Alumni.Include("Logs").FirstOrDefault(a = > ...

Is there a Linq to Entities debug Visualizer working?

I found this but this is not working for me.I added a reference and also tried to also copy it to this directory -\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers Has anyone tried using this or something similiar that helps me see the sql code generated by Linq query.I know I can use the profiler but I want something mo...

Why is LINQ to Entities making a subquery for me?

I'm using .NET 4 and the Entity Framework to construct a simple query. Here's the C# code: return Context.Files.Where(f => f.FileHash != 40) .OrderByDescending(f => f.Created) .Take(5); When I trace the query using ObjectQuery.ToTraceString(), I find the following subquery: SELECT TOP (5) [P...

How to enable sorting on a DataGridView that is bound to a LINQ to Entities query?

I have a query as such (simplified): var q = from t in _entities.Table order by t.Id select new { Id = t.Id, Name = t.FullName }; MyDataGridView.DataSource = q; However, it seems that I can't click on the Column Header and get it to sort (switching between ascending and descending) on...

.NET APP trouble writing group by and join clause with edmx

i have the following working query in mysql... select * from events e join performance_times pt on e.id = pt.event_id where pt.performance_date_only > '2010-08-10 00:00:00' group by pt.performance_date_only I am having issues getting the group by to work when using this with my edmx file in my mvc app. I have it working with the jo...

Problem with Relational Database in MVC Linq to Entities

I was hoping someone could tell me what is wrong here. I have three tables, LU_LOC_Suburb, Listings, ListingMessages. Listings has the following columns ID SuburbID (Coming from LU_LOC_Suburb) more... ListingMessages has the following columns ID ListingID (Coming from Listings) more... I'm trying to create a Messages page ...

Entity Framework 4 Lazy Loading When It's Not Needed; Using Wrong Key

I have a problem in EF4 where a query that I have returns the data that I want into an anonymous type, but when I try to move the data into a "real" type (I'm creating new instances of my EF objects) some data that the code has already pulled down from the database gets lazily loaded and for the lazy load it's using the key from the prev...

How can i insert dataset into sql table with same columns in Entity FrameWork?

i get all column values from Users to StandardUsers id,Name,SurName and PostCount data to add. But Return below error: IN " entityUsers.GetType().GetProperty(columnNames[i]).SetValue(entityUsers, columnValues[i], null);" Return To Me Error : Set method of characteristics not found. public static class MyDynamicInsertCustomerExtension...

Using "Match" in a Linq statement

I have a table that has two records (there will be many at runtime). The deviceId of the records are, “DEVICE1” and “DEVICE2”. I want to use a regular expression to extract records. The code below compiles but fails to return a result. When I hover the cursor on the “devices.ToList()” statement I get the following error, “base {System.Sy...