Questions tagged [linq-to-entities]

1

votes
4

answer
42

Views

Custom Sort Based On Referenced Records

Please consider these data: Id F1 F2 Ref_ID ------------------------------------------- 1 Nima 35 Null 2 Eli 33 Null 3 Arian 5 1 4 Ava 1 1 5 Arsh...
Arian
1

votes
1

answer
260

Views

LINQ with group by for nested list

I am trying to filter and get a list if my main object using Linq with my nested lists. what I require is - List class Category contains List and List But the result i get is grouped by both the child objects, hence i dont get the exact result. I want to group this seperatly to get the result. Below...
Praddy
1

votes
1

answer
185

Views

LINQ - Creating Subquery based on Where clause

I'm seeing behavior in LINQ that I just don't understand and I really want to prevent it from happening because it's causing my queries to run much slower than they should. The following C# code produces the results I'm expecting but when I add an additional dynamic filter to it things start to go s...
spyder1329
1

votes
0

answer
72

Views

LINQ - EXISTS, Reference Parent Field in Subquery

I'm working on creating a dynamic linq expression with an optional where clause containing 'exists'. Almost everything about this can be dynamic. The user can choose to filter only root level nodes or filter both the root and all descendant nodes. I've mocked up a working example of one of the pat...
spyder1329
1

votes
1

answer
75

Views

Project into a class with Private properties using Entity Framework

I'm using Entity Framework with a code-first approach to store data for a C# application I'm working with a SQL Server database. A challenge I'm currently running into involves a structure (approximately) like this: public class MainEntity { // Data public List SubEntities { get; private set; } } pu...
Kamil Drakari
1

votes
0

answer
112

Views

Create Exclude() extension method for IQueryable

I am using Entity Framework in my project. In some cases I need to get all the columns from the row, and some cases I need to get all the columns besides a specific in order to optimize speed and avoid querying a lot of data. For example lets say that I am saving emails in a table and I have the col...
juanora
1

votes
1

answer
109

Views

How can I avoid Entity Framework Core OrderBy a list property from doing a Top (1) per list item in the database?

I'm making a query to the database using EF Core 2.0.1 and in particular, the Microsoft.EntityFrameworkCore.SqlServer 2.0.1 NuGet package. Here are my models: public class Foo { public Foo() { Id = Guid.NewGuid(); } public Guid Id { get; protected set; } public IEnumerable Bars { get; set; } } publi...
chris31389
1

votes
0

answer
10

Views

Is it possible to project entities with 1-to-M children resulting in a single SQL query?

I am aware that by projecting (or 'shaping') the result in a LINQ-to-SQL or LINQ-to-Entities query, one can nudge the resulting SQL query to something more performant than without. Two excellent articles on this can be found here by Eugene Prystupa, and here by Rick Strahl. Note that in the examples...
Protector one
1

votes
1

answer
287

Views

must declare the scalar variable “@nInstID” [duplicate]

This question already has an answer here: Must declare the scalar variable 5 answers must declare the scalar variable '@custid' using dbcontext.Database.SqlQuery? 2 answers I am using a ADO.NET Entity Data Model for accessing my tables and stored procedure. I mapped stored procedure to my Room tab...
1

votes
0

answer
47

Views

EF Order by Nullable DateTime using string and nested reflection

According to this question I have created my methods for ordering data sets. public static IOrderedQueryable Order(this IQueryable source, string propertyName, ListSortDirection direction = ListSortDirection.Ascending) { return ListSortDirection.Ascending == direction ? source.OrderBy(ToLambda(prope...
Marek
1

votes
0

answer
158

Views

EF 6.0 with Symmetric key encryption

In my application I am using ASP.NET MVC with EF6.0. Initially we were saving data as a plain text. But because of some security reasons we had to implement Symmetric Key encryption with certificate on our database. And now because of that one we had to execute below commands before executing any L...
Stark
1

votes
2

answer
54

Views

Build LINQ query in a loop [duplicate]

This question already has an answer here: Dynamic where clause (OR) in Linq to Entities 2 answers I have a LINQ query (which will be executed against a DbContext), which I start off by building using some conditions I know of beforehand. var r = from p in db.People where blah select p; I then have...
md1000
1

votes
1

answer
57

Views

Table aggregation using linq (calculate Average value)

How to Aggregate below table using linq query Date tagname value 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(4) 54.73497 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(5) 3.417564 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT...
user7417866
1

votes
0

answer
57

Views

Mvc Custom Object from Detail Template

I sending the special model(object) to View. I am getting this error while displaying in View. Error: 'object' is missing an 'AracTakip' format var model = (from aractakip in db.Guvenlik_AracTakip join sirket in db.Yonetim_Sirket on aractakip.SirketId equals sirket.Id join arac in db.Guvenlik_Arac o...
Barış
1

votes
1

answer
65

Views

How to change a union function to a cut function? C# LINQ

The session receives input as a list of streets. * There is a table of streets, a table of countries, and a table that links countries to the streets. Now the function shows me all countries that have one or more of the streets that the function received as input. I need to change the function so th...
Neta R
17

votes
1

answer
9.4k

Views

LINQ to Entities does not recognize the method 'System.DateTime AddSeconds(Double)' method, and this method cannot be translated into

I receive this error on base {System.SystemException} = {'LINQ to Entities does not recognize the method 'System.DateTime AddSeconds(Double)' method, and this method cannot be translated into a store expression.'} on this code var eventToPushCustom = eventCustomRepository.FindAllEventsCustomByUniq...
GibboK
1

votes
1

answer
87

Views

LINQ To Entities SaveChanges() not working

I have a scenario where I have a form where I would like administrators to modify their exam / survey details, I am trying to update my database table with the following code. However the code does not save my changes for the 'if' part in my controller, and does not throw any error, and will just r...
Boby Williams
1

votes
1

answer
47

Views

LINQ to SQL (insert into fact table based on 3 tables)

I am not able to work with the below join. Idea is to find any new (AumProductId and IdClient) combinations from AceBiMonthlyDaos to create entry in Investment table with Unique Id, if those AumProductId and IdClient exist in Reference table of Instrument and Financial Account respectively. var resu...
SPG
1

votes
4

answer
107

Views

How can I make Sum() return 0 instead of 'null'?

I'm trying to use LINQ-to-entities to query my DB, where I have 3 tables: Room, Conference, and Participant. Each room has many conferences, and each conference has many participants. For each room, I'm trying to get a count of its conferences, and a sum of all of the participants for all of the r...
Jez
1

votes
1

answer
22

Views

Getting maximum date and return default date when table is empty

How to return date '1900/12/12 00:00:00' if table has no rows? I am trying to get max transaction date and it works well if there are rows in the table otherwise I get an error message because of date format in ToString(). string d = context.AllTransactions.Where(t => t.ID == OID) .Max(t => t.Transa...
user1263981
1

votes
1

answer
38

Views

Entity framework. Insert values from one entity class to another different one

Here is my problem... I've got one entity class, and I want to keep historical values from this table. Every time each record is changed, I want to insert a snapshot from this record into another table (with the same fields). I could do this field by field, but I'm sure there should be a simple way...
Arandanos
1

votes
1

answer
12

Views

Dynamic where clause using Linq expression having join with multiple tables

i have a linq query but in where clause is conditional. if eve.EventType is null then it will not include in where clause. How can we do with Linq lambda expression var data= (from reg in product join se in _order on reg.EventSessionId equals se.EventSessionId join eve in Event on se.EventId equals...
user2042214
1

votes
0

answer
56

Views

IQueryable returns inconsistent results

I have a relatively simple query which returns inconsistent results. Having a collection of id's (approx 3300), I want to query for the objects which have a child with that id. The relationship between my types is 1 to n. I do this in batches of 500. In my test, in the anonymous type in the Select...
Horea-Nicolae Soanca
1

votes
0

answer
40

Views

How to test whether my IQueryable will actually compile down to SQL

I have a project running on EF (6.0) and attempting to use OData to allow easy tabulation functionality. In order to achieve this, we have lots of vertical slices that are handling IQueryable right from the DbContext up to the Controller. We are mapping our domain models to VMs in those slices, whic...
Brondahl
1

votes
0

answer
18

Views

Oracle SQL partition selection in Linq-To-Entities

I'm trying to transpose this Oracle SQL query in EF using Linq-To-Entities: SELECT * FROM myTable PARTITION(p1); Problem is, how could I translate the partition selection ? I'm pretty sure there is no simple and easy way to do it, but I really need to select a single partition somehow. I need to sa...
Quentin S.
1

votes
1

answer
76

Views

Entity Framework query to get child items [duplicate]

This question already has an answer here: Loading all the children entities with entity framework 3 answers How to include() nested child entity in linq 3 answers I have order structure as below Order 1234 Category 1 Item 111 Item 222 Category 7 Item 444 How can I modify the query below to include...
mehwish
1

votes
1

answer
634

Views

Entity framework: One big model or a set of smaller models?

We been having some discussions on approaches to using the entity framework at work recently. We have a fairly large and complex n-tier web based application, which is due for a major overhaul. The question is: If we where to starting using the entity framework, would it be better to create one big...
Daniel M
1

votes
1

answer
1.1k

Views

Locating the getter and setter access modifiers in the EdmItemCollection of Entity Framework

I've been creating a nice T4 template for a repository pattern for my entities. Instead of manually parsing the xml in the edmx file I use the EdmItemCollection to create a object graph presentation for the conceptual model. I've been able to get a lot of information out of this model. But I cant fi...
Davy Landman
1

votes
1

answer
565

Views

Patterns or techniques for designing a flexible advanced search with Linq Expression Trees

I'm looking to add an 'advanced search' capability to my ASP.NET/SQL Server 2005 application. Ideally, I'd like it to be table driven. For example, if my schema changes with the addition of a new column to a table that I want to search, I'd like to have the UI reflect the addition of the new colum...
Howard Pinsley
1

votes
2

answer
3.9k

Views

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 (Dead Link) This is the exact output I want using Linq to Entities or Linq to SQL (image below): Image Link (Dead Link) When I use Linq to Entities or Linq To Sql,...
1

votes
1

answer
4k

Views

Linq to SQL - many to many mapping

In my project I have 'Player'(PlayerID and data) table, 'Games' table (GameID, Name) and I made a many to many table 'PlayerGames' (PlayerID, GameID - I created the forign keys relations) PlayerID and GameID are primary keys in their tables and the tuple (PlayerID,GameID) are primary key in 'PlayerG...
Yarin Miran
1

votes
1

answer
1.1k

Views

L2Entities, stored procedure and mapping

Finally checked out L2E framework and ran into problems almost instantly. Yeah, i know... i should read some books before. Situation: entity with props -> id and name. entity is mapped to table, which has id and name columns. sproc, which returns ONLY id column. Problem: ObjectResult result = _con...
Arnis Lapsa
1

votes
2

answer
3.1k

Views

How to display Linq to Entity query result in ASP.NET MVC view

I have a Link 2 Entity query expression in my ASP.NET MVC app: Dim var = From c In context.Evaluation_Template _ From ae In context.Assigned_Evaluation _ Join ua In context.User_Assignment On ae.Assignment_ID Equals ua.Assignment_ID _ Select c.Evaluation_Name, ae.Due_Date, ua.Is_Started, ua.Is_Compl...
CoolGravatar
1

votes
2

answer
1.6k

Views

Linq Evaluate Nullable types in select clause

I get a weird exception: 'Unknown Expression type: IIF(e.Accredited.Value, 1, 0)' running the following statement: var x = from e in _EntityManager.TrainingCourses select new { Disabled = (e.Accredited.Value ? 1 : 0) }; Please help!! How do I evaluate a (bool?) in the select Thanks
1

votes
1

answer
1.4k

Views

ApplyPropertyChanges and References

I asked this question earlier but I think I phrased it incorrectly, so here is attempt number two. I have the following code: public User EditUser(User userToEdit) { //userToEdit contains values for eagerly loaded contacts entity User originalUser = (from u in _entities.UserSet.Include('contacts') w...
Graham Conzett
1

votes
3

answer
1.1k

Views

Ado Net Data Services BeginExecute Problem

public void metodoX() { foreach (TURNO t in listaTurnoPersona) { DataServiceQuery query = General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA.Where( z => z.ID_TURN == t.ID_TURN && z.FE_CALE >= RadDatePicker1.SelectedDate.Value && z.FE_CALE
1

votes
1

answer
1.6k

Views

Linq to Entities Left Outer Join/ Subquery?

I have a query (developing in linqpad): DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime previousMonth = currentDate.AddMonths(-1); DateTime previousMonthForAveragePrices = currentDate.AddMonths(-2); var help = from cd in CostDrivers.OfType() where cd.isActiv...
1

votes
2

answer
330

Views

MVC using Linq to Entity w/ sql encryption

Currently i am using sql encryption and would like to continue using it through Linq. I have all my CRUD stored proc's wired up to the table in order to handle the encryption/decryption on the backend. Problem is my database model see's a field type of varbinary(max) which is used for the sql encr...
1

votes
1

answer
984

Views

dynamic linq contains

i search for a dynamic linq-to-sql Contains (StartsWith / EndsWith) method. I’ve tried the following code, but it didn't work. Any ideas? public static IQueryable WhereContains(this IQueryable queryable, string propertyName, V propertyValue) { ParameterExpression pe = Expression.Parameter(typeof(T...
1

votes
1

answer
891

Views

Query Builder vs Linq to Entities

I have been hearing that the built-in query builder for the Entity Framework is much faster than Linq to Entities. Is this true? If so, can I use the query builder for any type of query?
user161433

View additional questions