Questions tagged [linq-to-sql]

Use this tag for code reviews of or involving Linq to SQL classes, mappings and associations, or for code reviews of or involving querying a System.Data.Linq.DataContext object with Linq statements.

Filter by
Sorted by
Tagged with
0 votes
1 answer
131 views

Linq Conditional where clause when parameter can be null

I need to filter my records on the basis of "courseId" which is passed as parameter - Here is my code - ...
user avatar
  • 335
1 vote
2 answers
86 views

Exporting test results to PDF tables

I have an asp.net web application and I want to export to a PDF tables in a particular way. Tables will have data of type Test. tests have a type(by type i mean an int to tell them apart) and for ...
user avatar
  • 13
0 votes
1 answer
62 views

Data validation for to check required fields are mapped

Can I break the below foreach and IF statements into LINQ expression. Also, performance wise which will be better. Please suggest. ...
user avatar
5 votes
2 answers
3k views

Efficiency of a linq query on a nested structure

For a survey website I've written this query to show the survey results, with a percentage for each chosen answer: ...
user avatar
1 vote
1 answer
79 views

Aggregating clients and client types

The code I have put together achieves what I want, but I don't know if it is the right way to go about tackling the problem. I am dealing with 2 tables (CLIENT, CLIENTTYPE) each of which I have an ...
user avatar
1 vote
1 answer
4k views

Selecting employees in certain departments using LINQ

I am trying to select the DepartmentName from Employee Table based on where condition. Is any way to simplify the code? ...
user avatar
  • 129
3 votes
1 answer
597 views

Search products from database on base of search filters

I am writing a code to search Product database and return result to user. user can select various options like product attributes that varies from product to product, also there may be case like for ...
user avatar
9 votes
6 answers
9k views

LINQ to SQL query filter, with the name match ignoring multiple punctuation characters

I have the following LINQ to SQL query which works fine but looks ugly: ...
user avatar
3 votes
2 answers
463 views

Implementing SOLID Principles - LINQ TO SQL

I have been using Layered Architecture in my web application. Can anyone please advise if my data layer classes (both Linq and booking class) can be improved? I have just started learning about solid ...
user avatar
  • 131
8 votes
1 answer
3k views

GET with paging, sorting and filtering

I have a GET method that handles paging, filtering, and sorting. Development has been fairly rapid and I'm not completely sold on some of the implementation. A few assumptions have to be made for this ...
user avatar
  • 83
1 vote
1 answer
7k views

Calculating the .Sum() in Linq-to-SQL

I have the following code where I need to execute 2 Linq-to-SQL statements. If I do not have the Any() in the if statement, then ...
user avatar
  • 157
1 vote
0 answers
62 views

LINQ SQL query to display the status of tracked computers

This is my existing LINQ SQL. At the moment it works, however the using the coalescing operator for null results on the "let" clauses make me feel like I'm violating some sort of unwritten rule. Is ...
user avatar
3 votes
1 answer
2k views

Returning an IEnumerable using Linq-to-SQL which is then bound to a GridView

This function works, but it's really really slow and the generated SQL is gargantuan and horrible to look at. It's also very expensive to run when it shouldn't be. ...
user avatar
1 vote
1 answer
456 views

Eager Loading Deeply into a Model with a Collection Property Whose Type is Inherited

Visual Studio generated this great route for me, where I can load an entity: ...
user avatar
  • 133
4 votes
1 answer
11k views

Simplifying a LINQ expression that finds the largest date smaller than another date

I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the ...
user avatar
  • 565
7 votes
3 answers
226 views

Fetching a set of event IDs from a database based on a set of company IDs

The following code fetches a set of company IDs from a database if there are any events associated with a company that has a missing property. Because the set of company IDs is embedded into the SQL ...
user avatar
  • 711
4 votes
2 answers
36k views

Linq-to-Sql Contains an int? inside a list of int

Curious if there is a better way to write a repository method that receives argument List<int> and checks if the database ...
user avatar
3 votes
4 answers
380 views

Website news message edit panel

The explanation I'm making a website for a hypothetical theatre to get a better feel of MVC web-applications in ASP.net. The idea is that there are newsmessages that are displayed on the homepage, ...
user avatar
4 votes
1 answer
147 views

Inserting customer care database analysis detail records

I have written this linq-to-sql query to insert a bunch of customer care database analysis detail records: ...
user avatar
2 votes
2 answers
663 views

Delayed Include rules for EntityTypeConfiguration using LINQ expressions

The aim of this class is to set rules for including navigational properties on Configuration level and then apply where needed in the code. I've decided to store expressions in the list for different ...
user avatar
  • 121
2 votes
1 answer
12k views

Converting table data into nested JSON

I'm new to C# (coming from a JavaScript background) and it seems like this code could be greatly improved. This SQL query: ...
user avatar
  • 121
3 votes
2 answers
6k views

Checking for user permissions

The idea here is we have Roles, Permissions, and a table called PermissionRoles that connect the two. So a Permissions can be in many Roles, and many Permissions can have the same Role. So what the ...
user avatar
3 votes
2 answers
1k views

Linq-to-SQL DAL on a Windows Forms project

I just started out a new job as a C# programmer on .NET 3.5. My manager gives me total independence on how I build my modules, which is generally a good thing, but there are minuses too. Having too ...
user avatar
3 votes
1 answer
316 views

Extension method to do Linq Lookups

Does this extension method contain unnecessary work? - Thanks for reviewing Scenario - A series of tables are Key-Value pairs (Int "Id" / nvarChar "Title"). This extension method "dots-off" any ...
user avatar
  • 145
0 votes
1 answer
818 views

Simplify IQueryable Linq to SQL query

Below I present to you an IQueryable LINQ to SQL query (used with NHibernate). I have tried to simplify this query but I could not do it. I want to run a query for searching information. Options: ...
user avatar
3 votes
1 answer
957 views

Why is loading images taking so long?

When Page_Load is executed I assign the ImageUrl which is a IHTTPHandler: ...
user avatar
3 votes
3 answers
583 views

Code optimization by constant if-structure iteration removal

Below you will find the specific code that I am attempting to optimize. I have a method previous to called getCount() which, based on similar parameters as below, ...
user avatar
2 votes
2 answers
1k views

Linq C# pulling from table row into input fields

Today is the first time I've used Linq, so I wanted to get a code review on this and make sure I'm going about it correctly. I'm filling text boxes and dropdown lists from a table row. ...
user avatar
12 votes
1 answer
601 views

Password Manager UI: Populating DataGridView is Painfully Slow

I'm designing a small account/password manager using C# and SQL Server CE. LINQ to SQL is my ORM of choice. Here's the data model representing how the SQL Server CE database is set up: And here's my ...
user avatar
7 votes
2 answers
15k views

A generic way to use LINQ to Entity with types and operations unknown until run time

A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs. Here's what I am trying to accomplish: I'm writing back-end support ...
user avatar
  • 171
7 votes
1 answer
2k views

Redundant DataContext ? - LINQ to SQL

This seems like a pretty basic question, so bear with me...Say I have two (or many) methods in the same class that need a LINQ to SQL DataContext. Additionally, I am needing the DataContext in other ...
user avatar
2 votes
3 answers
185 views

How to make my code faster and easier?

This is my .cs part code where I am calling storeprocedure in LINQ to SQL: ...
user avatar
  • 131
8 votes
1 answer
406 views

Does this unusual data access pattern create any problems?

The background Two beginners without access to an experienced mentor write an ASP .NET MVC application, mostly simple CRUD, using Linq to SQL for the data access layer. Beginner number 1 writes the ...
user avatar
  • 201
3 votes
1 answer
369 views

LINQ statement to aggregate data

Teachers can raise 'dramas' which are when students forget equipment, don't do homework or are flagged for concern. Each drama for each student is stored as a separate record. I seek a list of all ...
user avatar
  • 450
7 votes
1 answer
473 views

Comparison table for comparing products

I'm attempting to create a comparison table to compare products depending on the add-ons they have. To grab the data and filter it I'm using LINQ To SQL. Table's Layout (cut short): ...
user avatar
  • 71