Questions tagged [linq-to-entities]
This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.
6,801
questions
0
votes
1
answer
44
views
How to update projections in EF?
I am doing a projection using linq, the projection is supposed to convert my query data into an expected object, so I want to use automapper to edit my promotion object but automapper does not perform ...
-1
votes
1
answer
37
views
LINQ to entities query with count of parent depending on optional child collection
I have to found the count of Table1 such that
Table1
Table2(optional)
Table3(ICollection) where one column has matching value
Table4 (optional)
Table5
Table6(...
1
vote
0
answers
26
views
Query with GroupJoin method can not be translated [duplicate]
I am traing to get identity users with roles using GroupJoin
I am getting this exception
System.InvalidOperationException: The LINQ expression 'DbSet()
System.InvalidOperationException: The LINQ ...
0
votes
0
answers
19
views
Strategy for using EF Core query, SQL and local
Background:
I have two tables, stored in SQL Server, that contain a list of items (about 50,000 items) and localized (translated to specific languages) text associated with each item. So, this is a ...
0
votes
1
answer
23
views
How to execute Linq to EF to search for string in a comma separated string field & replace the matched value in comma separeated with empty string?
I have a class as below. I want to remove the Id value from the comma separated Colors if the endDate<currentdate using linq to EF in .net. So for the 2nd item, Id=2,replace remove 2 from Colors of ...
0
votes
1
answer
33
views
Can I select two columns into hashsets in a single query?
I have a table that looks like this,
I want to get hashsets of Column 1 and Column 2 respectively.
Id
Type
Provider
1
car
provider 1
2
motor
provider 2
3
bike
provider 2
Currently, I'm doing this:...
-1
votes
0
answers
28
views
Get list of children with parent (without mapping ) into new object
I have two classes such as:
public class Parent {
public int Id { get; set; }
public int Title { get; set; }
}
public class Child {
public int Id { get; set; }
public int ParentId { ...
2
votes
0
answers
43
views
.Contains() in .Any() EF Core 6 doesn't work and gives crash of unsupported client evaluation
I have a query which used to work fine in Entity Framework but when we migrated to EF Core 6.0 it crashes due to unsupported client evaluation, I think it's something with contains inside Any () but I ...
0
votes
1
answer
46
views
Entity Framework to EF Core 6 migration query not working
We are migrating our ASP.NET Framework Web Api project to .NET 6 and after fixing all build errors while running the project it starts giving errors in EF queries related to EF Core 3.0+ does not ...
0
votes
1
answer
38
views
.NET 4.8 + checking equality between two generic type parameters in the Where clause
I am implementing repository pattern for an application i'm building, where my base repository is composed of two types: TEntity and TKey.
TKey is struct and TEntity is a custom class named: ...
0
votes
0
answers
20
views
Filter IQueryable by values from another database using EF
I have two databases. I need to fetch some data (property values) from a first database and then filter out the records from a second database by those fetched values.
Now I am afraid that this ...
-1
votes
0
answers
29
views
How to rewrite GroupBy in in result selector?
I wanna transform this IEnumerable:
public class PaymentInfo
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public ...
1
vote
1
answer
44
views
Entity Framework with multiple LEFT OUTER JOINs where one "joins" on to the other
I'm relatively new to EF, so my apologies if this is an EF 101 type of question. I have a SQL query that I'm trying to convert to C#. The following SQL query returns 290,903 records:
SELECT clcl....
0
votes
1
answer
45
views
OrderBy produces an ambiguous call between the following methods or properties
I'm trying to do OrderBy, but receiving the following error:
The call is ambiguous between the following methods or properties: 'System.Linq.Dynamic.DynamicQueryable.OrderBy(System.Linq.IQueryable, ...
0
votes
0
answers
21
views
Mapping multiple select statements from stored procedure into single object - EF
I am using Entity Framework Code first. I want to achieve the following: I have the following class structure:
public class BasisdatenkatalogDto : DtoBase
{
public List<TeilstatStationerDto> ...
0
votes
1
answer
79
views
Linq query for getting group by values in columns
I have total 3 tables in which I have data as
Vendor master table has list of vendors
Category master table that has list of categories.
Product master table that has product details and foreign ...
1
vote
0
answers
13
views
Issue in searching a name in entity framework model using code first approach
I have the following code to retrieve a name when a user enters the name in the search box and the function searches the name from Student model. Please find below the code. However, it doesn't show ...
0
votes
1
answer
37
views
Get rows according to given value
I have mssql table as the given image. I want to know how can I return rows from the table tblSpace that the sum of "Available" rows is greater than or equal to given value using Linq. Also ...
0
votes
0
answers
54
views
EF Core: how to make a request better
I have a table Device with 1M records. Table has approx 40 columns, for most requests need only 10 of them.
The table has relationships with:
Carrier table with 1000 rows and 50+ columns.
DeviceModel ...
0
votes
1
answer
69
views
Why does this exception throw when calling a local variable in a where clause of a linq expression?
I want to execute this LINQ query, but since I've changed a hardcoded 5 to firNr (a local variable) in a where clause, I'm getting the following error:
System.AggregateException: "One or more ...
0
votes
2
answers
59
views
Linq Select new with GroupBy and OrderBy
For the given data set, I want to return the unique rows for each OrderId that has the lowest number for Status, so the result would be:
I have a working query that does that:
var result = _dbContext....
0
votes
1
answer
40
views
Operand Data type float is invalid for modulo operator, float to int with LINQ
I was trying to fetch data from Sql using LINQ and do some operation like rounding of my number to nearest 1000 when the value is greater than 500. I have the column costreproductionnew(float,null) ...
1
vote
1
answer
32
views
xUnit test fails while comparing Lists
Here is my unit test and it fails with a message.
Kindly help me fix this.
Update Question:
It looks like i am trying to unit test the JsonSerializer.Deserialize method. So is this a legitimate unit ...
3
votes
1
answer
238
views
EF Core Function to Pass "AS" in `CAST( 'value' AS VARCHAR(1024))`
I have a piece of code in EF Core that looks like this:
var queryPart1 = from table1 in context.Table1
select table1.ColA;
var queryPart2 = from table2 in context.Table2
...
0
votes
0
answers
20
views
Using LINQ to EF to return max date row from outer joined table
The problem is pretty simple:
One PaRequests has zero or more PaRequestComments. The PaRequestComments has a timestamp column (named [when], not I didn't name it!) which is 'when' it was created.
The ...
0
votes
1
answer
54
views
How to update a row that already exists in the database?
When updating a row that already exists in the database via an Excel file upload and EPPlus, a new row is being created instead of updating the data that already exists.
How can I update the existing ...
0
votes
1
answer
25
views
LINQ querying different DataSets, based on input parameter
I've battled this question for quite a while now, and I really want to know if it's possible or not. This is my current code, but I really don't like using a switch case. Is there a way of getting ...
0
votes
1
answer
23
views
Is it possible to select mapped entity into another mapped entity in a single query?
Is there any elegant way to perform a nested LINQ selection into objects that are being selected themselves? In other words, let's assume there are three DB tables all with one-to-many relation: ...
0
votes
1
answer
55
views
SQL says no active transaction even though I created one
Using Microsoft.EntityFrameworkCore version 6.0.5, with .NET 6, I'm doing multiple database operations inside of a transaction. When I call CommitAsync, it fails saying:
Cannot issue SAVE ...
0
votes
0
answers
11
views
orderby or orderbyDescending on Expression column not working in LINQ
var q4 = await dbentity.tbltest.Where(v => v.Nvcode == vcode)
.OrderByDescending(o => Convert.ToInt32(o.Period.Substring(5, 4)))
....
0
votes
1
answer
69
views
Filter List inside List Linq
I have list say list of customers and inside each list there is another list of orders
Class Customer
{
int ID,
string Name
List<Order> orders
}
Class Order{
int ID,
string Name
}
Also have a ...
0
votes
1
answer
46
views
Can you filter an Entity Framework DBSet by a value in the many part of a one-to-many relationship?
I am trying to filter a DbSet by a value that is in the many part of a one to many relationship. For example, I need to get the entire list of students. Each student can have many classes. I need to ...
1
vote
2
answers
154
views
Entity Framework: Getting exception while inserting row in MySQL Table
I recently switched my database from SQL Server to MySQL. I am still using Entity Framework 6 to do CRUD operation in database. When I was using SQL Server as backend then I was setting "...
1
vote
1
answer
50
views
EF Core Accessing a list relation
i have a question about ef core query and ill be appreciated if you friends can help me ! i have a .net core mvc project , that has three (classes) tables including , Products , Groups and ...
1
vote
0
answers
181
views
Is Using EF Core Value Converter Preventing the Contains() LINQ Method from being Translated to SQL?
I have a Movie class. It has a Genres property of type List<string>. I use this exact EF Core Value Conversion to store it in the database as a comma-separated string.
In my method, I have ...
0
votes
0
answers
22
views
Evalute part of LINQ expression before translating to SQL statements
Dim instanceOfMyClass As New MyClass()
'... Some code to manipulate instanceOfMyClass.MyArrayField
Dim thisYear = DateTime.Today.Year
Dim records = (
From i In dbContext.MyTable
Where i.MyCol >=...
0
votes
0
answers
32
views
How to join multiple tables using linq with group by condition
I want to fetch the list of employer with inner list details to show multiple address. I have tried the following code and can able to fetch the EmpConnectionNumber, EmpState. I could able to fetch ...
1
vote
1
answer
30
views
LINQ to Entities - Get results based on join, conditions and sorting
I have some code that loops through records of 3 separate lists and performs logic to create a new object. It works but takes a very long time. I'm hoping I can simplify it all into a LINQ to ...
0
votes
1
answer
50
views
Lamda Link type arguments cannot be inferred from usage
we are using entity and I am trying to join 2 tables on 2 columns. an id and server id. My original query didn't account for server (which is what i'm trying to fix)
var client = _Context.Address
...
1
vote
1
answer
56
views
LINQ to Entities: pattern for null parent
I'm querying an Entity Framework model, so In this case, I'm using LINQ to Entities. It just means I can't use all of the latest operators.
Here's a LINQ select statement:
var nodes = r....
0
votes
1
answer
23
views
Control a reference in entity framework?
enter image description hereControl a reference in entity framework
Open question .Net Core 5 - Entities.
What do you think is the most efficient way to work in MVC mode, having 1 single entity that ...
0
votes
1
answer
75
views
Linq: filter Ids from a list of class
I have a list of Customers class
class Customers
{
int Id
string Name
}
List<Customers> CustomerList
Lets suppose this list contains 10 records.
I have to filter by the Id in the CustomerList ...
-3
votes
1
answer
36
views
Error on converting string to datetime as part of Where condition [closed]
In my ling query I am trying to do like below
}).Where(r => r.dueDate ==
DateTime.Parse(ConfigurationManager.AppSettings["1000"])).ToList()
But I am getting below error
LINQ to ...
-1
votes
1
answer
46
views
Linq Join() method with left join and grouping
I am trying to join two tables with grouping as per following sample. What i need to do is to apply Left join. tried several times but failed
var _result = _parents
.Join(_childs, ...
0
votes
0
answers
77
views
Entity framework left outer join with filtering
I'm using Entity Framework. I have two tables which are linked in my model. So, I'm using LINQ to Entities to query the data and navigation properties as the joining method in this instance.
My two ...
0
votes
1
answer
208
views
How to Order Data Query in Entity Framework Table Relationships LINQ Method syntax?
I am having a problem ordering data by table Iscinstances row Name in table relationships, the Iscinstances table is JOIN in LinkUsersToIscinstances table, below is my query for the table ...
0
votes
1
answer
57
views
Select from a list all the skus that match id and colour LINQ selector [duplicate]
I have a database that I'm connecting to using EF Core.
Table:
Id Sku Colour
--------------------
1 123 blue
1 124 black
1 125 green
2 126 yellow
2 127 red
3 ...
0
votes
2
answers
71
views
How to get item from a list that position in a certain place
Please consider this scenario:
For some math calculations I should find a number in specific place in a sorted list. For example consider this list:
1 - 2 - 3 - ... 17 - 18 - 19 - 20
I should to find ...
0
votes
1
answer
276
views
Dynamic filtering using Linq in ASP.NET Core
I am new in Linq query. I just want to make my filtering dynamic if 1 of the fields or more in image attached is/are null:
Since I am used to hardcode query, I can't derive the code if I only choose ...
1
vote
0
answers
29
views
In EF 6 DBInterception, how to get the actual value from DbModificationClause clause?
I'm researching with encrypting an EF 6 db column using db interceptors and custom annotation on the ef entity: https://www.codeguru.com/csharp/soft-deleting-entities-cleanly-using-entity-framework-6-...