Questions tagged [linq-to-sql]
This tag is NOT ABOUT LINQ TO SQL TRANSLATION! Linq to SQL is an old ORM that's part of .Net framework, not core. For questions about LINQ to SQL translation please use the tag of the ORM in question.
14,806
questions
0
votes
0
answers
3
views
ExecuteCommand in data linq query
I use ExecuteCommand in data context in linq to pass update command like this
_context.ExecuteCommand("update tb_ExpList set exp_name = '" & TextBox8.Text & "',exp_desc = '"...
-1
votes
0
answers
32
views
EF.CompileQuery: 'The LINQ expression ... could not be translated'
I have a function something like this
public static Func<DBContext, ViewType, IEnumerable<DBObject>> GetVehicles =
EF.CompileQuery((DBContext context, ViewType viewType) =>
...
0
votes
1
answer
46
views
C# EF Core - Query must contains all in the List<object>
class OrderItem
{
public long Id,
public int Qty,
public long ProductId
}
class Order
{
public long Id
public ICollectable<OrderItem> Items = new List<OrderItem>
}
var dtos = ...
0
votes
0
answers
23
views
LINQ to SQL group by not working on State -> County grouping
Not sure why this code is not working?
I have three tables. A state table, a county table and an event by state table.
I want a list of the counties in each state for the event ID I'm filtering on.
...
0
votes
0
answers
22
views
Dynamically select fields based on result object as a combination of base and derived class
I've got a couple of classes I need to return data from.
public class Person
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public ...
0
votes
0
answers
39
views
Error when adding Linq to Sql class it says "A file with name studentdb.dbml.layout already exist."
Whenever I'm trying to add LINQ to SQL class as a new item in visual studio 2022, then every time it shows an error by saying "A file name studentdb.dbml.layout already exist. Please give us a ...
1
vote
1
answer
70
views
HotChocolate v.13 [UseProjections] attribute does not work with DataLoaders
I have the following GrapqhQL query:
query {
listTenants {
totalCount
items {
tenantId
name
sites {
totalCount
items {
siteId
cmxName
...
1
vote
1
answer
49
views
.Net linq2db, fluentMappingBuilder, table name not apply for query
I'm diving into a little project with linq2db. I've set up models, a connection, and a simple query. But here's the thing: every time I run the query, linq2db uses the table name from the entity model,...
0
votes
0
answers
16
views
Generating designer.cs code class for a DBML file using Pre build event in Visual Studio 2022
Question:
I have a DBML file located within a Data\Linq folder in my Visual Studio 2022 project. I'm aiming to automatically generate the designer.cs code class for this DBML file using the Pre build ...
0
votes
1
answer
49
views
How to know which LINQ statement produced the SQL at runtime Or Is there a way to inject a unique string into every Linq statement
I'm writing an ASP.NET application that uses EntityFramework 6.4.4 version. I'm having trouble debugging a Linq statement that's causing an error. I want to be able to see the C# Method that was ...
1
vote
2
answers
100
views
How to convert SQL query values separated comma to list by using entity framework core 7?
I work on asp.net core razor page . I face issue How to convert complicated sql query to entity framework core 7
Exactly I need to convert this SQL statement to LINQ to entity without write SQL ...
0
votes
0
answers
16
views
Linq to SQL ignore loading options
I use to prefetch data using loading options, so that the communication with the DB do not become too chatty.
Everything work fine but when i use ExecutyQuery (instead of LinqToSql query) the loading ...
0
votes
1
answer
26
views
SonarQube Issue: Adding CultureInfo inside Linq queries
I am working on SonarQube issues on my .net core application. I have an issue with the sonarQube report which asked to add cultural info in Convert Methods like ToString(), ToUpper(), ToLower(), etc ...
0
votes
0
answers
35
views
Entity Framework 6 Ignoring Distinct in SQL Query when Selecting Multiple Columns
I am not seeing the expected sql generated for Linq to SQL with regard to Distinct when selecting multiple columns. In particular the Distinct is being left out of the generated SQL. Strangely, this ...
3
votes
2
answers
118
views
ToListAsync() vs AsEnumerable() in terms of synchronicity
Let's say I have the following method:
var result = (await db.Students
.Where(s => s.Name == "Foo")
.ToListAsync())
....
0
votes
1
answer
33
views
Selecting from a Complex View takes a long time in Linq
I am trying to select data from a complex View, but the query materialization takes a long time (4 seconds).
This is the Code:
// 1. Perform a Search by name on tbl_member
var ...
0
votes
1
answer
28
views
Expression predicate with parameter on mandatory string
I'm creating a predicate dynamically for a LINQ-to-SQL query. This predicate is based on a string property (NOM). If I make this predicate with Expression.Constant(value), the SQL generated for the ...
0
votes
1
answer
20
views
LINQPad query does not return result when using GroupBy and First or FirstOrDefault (semicolon)
In LINQPad 7 a relatively simple GroupBy query returns results but when you add First() or FirstOrDefault() - the result is not returned.
(Processes is the table I am targeting in this example but I ...
1
vote
2
answers
49
views
How to Order Conditionally in Linq EF Core?
How can I write OrderBy conditionally?
As you can see in both if and else condition entire linq is same only orderBy is different.
In first case I am ordering in ascending and in second case I am ...
0
votes
0
answers
24
views
How Can Prevent Includes Of Childs inside Items again After Make Conditions in includes
I have some Filters of item and item contain details List of invoice,
The code is:
var query = _itemCardRepository.GetTableNoTracking()
.Include(x => x.AllInvoicesDetailsList)
.ThenInclude(...
0
votes
1
answer
27
views
linq query to get list of friends
I can't create a request to get a list of friends where name or surname like "param". The main requirement is that request has to take all friends with param of name or surname, not all and ...
0
votes
1
answer
28
views
How to bind different values from a list into another list on the bases of Key using Linq
I am working on application where I am receiving data shown in demo list below.
var dd = new List<ConfigurationItem> {
new ConfigurationItem {
Key = "Partners:JohnDeere:...
-2
votes
1
answer
21
views
Convert SQL query to LINQ with subquery
I don't know linq but I need to create a linq query for this SQL query
SELECT a.[ProjectId],
a.[CompanyId],
a.[Status],
ISNULL((SELECT TOP 1 1
...
1
vote
2
answers
143
views
Error projecting from a grouped linq query
I have a database table that stores the following data regarding images:
public class EventImage
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EventImageId { get; set; }
...
0
votes
0
answers
37
views
Handling NULL check and assign default if NULL in LINQ
I have below SQL query trying to convert it to LINQ:
if exists(select top 1'x'
from tblCallerDetails
where cId = @cId
and bId = @bId
and pId =...
-1
votes
1
answer
56
views
How to convert plain object to nested sub object using Linq to SQL C#
I am working an application where I am receiving a plain list from database which I need to convert into the following JSON object. Here is what I have tried so far. I am not willing use nested ...
1
vote
1
answer
67
views
LINQ expression translation issue with GroupBy and where
I am trying to get all items in database that have a duplicate owner. My first method returns their count and works without any issue:
public int GetUsersWithMultipleItemsCount()
{
return ...
0
votes
1
answer
23
views
(C#)MVC5 EF6 Ordering a collection and ordering sub collection in each item
I'm trying to order a collection of News Entities and each item has a subcollection of NewsComment I'd like to order. I've tried a few things, this is what I have right now, what am I doing wrong?
I ...
0
votes
1
answer
31
views
Linq to SQL calculate average and count with a join
I am trying to calculate the average rating for a product category and the total number of ratings received. In the example below, I would like to get the average rating/count for the shirts category....
0
votes
1
answer
90
views
Convert from LinqToSQL to Linq2DB
I have a project where an existing SQL Linq connection and full DBML has been created. Now I need to convert this same code to access from MySQL (Don't ask why... it's complicated).
I have install ...
0
votes
0
answers
43
views
Creating a list of tags: is it better to create two tables or add a column?
What is the best LinQ to SQL query between these 2 designs
Design 1
var result = orders.Where(o => o.tags.Contains("blue"))
// Where Tags is a string of tags separated by a coma: var tags ...
0
votes
0
answers
48
views
Linq not be able to understand the alias in nested select
FindAll() is a function which gets table data as IQueryable.
Here when I run the query I got the following error LINQ expression
'x' error could not be translated either you need to rewrite query to ...
0
votes
1
answer
33
views
System.Data.Linq.Mapping.AttributedMetaDataMember High memory consumption
I'm analyzing the dump file for the Windows service project, and it is using LinqToSQL to connect databases. Attached dumpe heap memory analysis summary.
I can see the System.Data.Linq.Mapping....
0
votes
0
answers
57
views
Linq to SQL use view instead of query
I have an entity in linq to SQL that i query. The query result, of the kind IQueryable is passed through repository and is manipulated in various way.
I noticed that the first query i do, to fetch the ...
2
votes
0
answers
193
views
Linq to SQL tools in Visual studio 2022 Community and Pro
I'm installing Visual studio 2022 (I tried with Community and Pro) in a Windows 11 (virtual machine on macOS - Parallels desktop) but i can't find Linq to SQL Tools under Individual components, Code ...
0
votes
1
answer
67
views
Error thrown while trying to update linq-to-sql object
I am using ASP.NET MVC 4 (aspx) using MSLinqToSQL as the connector to MYSQL database. I am trying to update the StatusID of an object based on certain criteria.
The criteria is simple, the current ...
0
votes
0
answers
15
views
any improvement in following linqtosql query where i shouldn't need select if possible
following is my query
return await (from ofr in _context.table1
join aca in _context.table2
on new { a = ofr.f1, b = ofr.f2}
...
1
vote
1
answer
40
views
Linq to SQL delete a record from database taken from another context
The following code:
var record = GetDatabaseRecordByID(UniqueObjectID);
if (record != null)
{
using (var db = new DBContext())
{
db.GetTable(typeof(T2)).DeleteOnSubmit(record);
...
2
votes
0
answers
50
views
LINQ to SQL one to one relation anomaly
I am a bit confused by the behaviour of LINQ To SQL (just for clarity I do not mean EntiyFramework or LINQ To Entity but old LINQ To SQL).
I have a relation between Entity and Resources. Entities are ...
0
votes
1
answer
68
views
Linq to SQL parent-child relation direction
I have a parent-child relation among two tables named: Relation and Resource, so that Relation.RESOURCE_ID == Resource.ID
If I write my association into the dbml file, so that Relation --> Resource ...
0
votes
0
answers
174
views
Linq to SQL producing LEFT JOIN instead of OUTER APPLY
I wrote following query which produces an OUTER APPLY when translated to SQL
Users.Where(u => !u.IsDeleted).Select(u => new
{
User = u,
Requests = OfficeRequests.Where(x => x....
-1
votes
1
answer
263
views
How to concatenate a date and a time string and compare with a DateTime using LINQ
I have two strings, one of them for time only and the other for the date. I compare the concatenation with a DateTime.
I want to translate this SQl query to LINQ:
select count(*) from ViewAllTranUser
...
0
votes
0
answers
77
views
.NET - LINQ to SQL - Insert multiple lines into a child table after inserting multiples lines to his parent table
my problem is simple but hard to achieve. I'm building a translation dictionary based on italian translation.
I have a PARENT table that is structured like this:
[Id] [int] IDENTITY(1,1) PRIMARY ...
0
votes
0
answers
60
views
How we can call a stored procedure one time instead of 3 times in C# to assign result to different variables?
I have a function in C# where db2.case_bill_totals is called three times with different timestamps as parameter and store their value in variable so can use on next step. Is there any way to call that ...
0
votes
2
answers
71
views
Linq to SQL Dynamic Where Clause
I have a simple query:
dim res = (From x In db.INVENTORies
Where x.INVENTORY_ACTIVATION_DATE IsNot Nothing).count
I need to run this for 14 different date fields, so how do I run this where ...
0
votes
1
answer
177
views
Linq join using split in condition
I'm a newcomer in Linq C#.
I have a scenario where I need to check part of a sentence is equal to another value of the field.
I use IndexOf to get part of the sentence in the left join condition. The ...
0
votes
1
answer
20
views
LinqToSQL: Exclude data from another table, but based on a combination of fields
I have a result set of users in a particular position.
Now if I want to exclude users from another list that contains a list of users, this will work:
var toExclude = dc.Users.Where(p => p....
0
votes
1
answer
19
views
Binding source does not reflect external changes to the database
I have a table Table1 with a single varchar Field1 and the following content:
Andy
Bob
Chris
Dave
Now consider the following code, that uses a linq-to-sql datacontext:
private DataContext dc = new ...
0
votes
1
answer
90
views
Why is my database throwing primary key violations after migrating to Azure?
Background: I have an old Windows VPS with SQL Server and IIS and whatnot that has been serving this web app for years. Along the way I've upgraded SQL Server and Windows occasionally.
Last night, I ...
1
vote
0
answers
45
views
Linq to Sql query self join with grouping c#
I have following tables
Machine table
public class MachineUpdate : DbContext
{
public int MachineUpdateId { get; set;}
public int MachineId { get; set;}
public string MachineName { get; ...