Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:10:40+00:00 2026-06-14T22:10:40+00:00

I have to make some queries in C# using LINQ. I tried my logic

  • 0

I have to make some queries in C# using LINQ. I tried my logic with a SQL request. It looks like this:

SELECT DISTINCT test_laktationen.lom, test_laktationen.laktanfang, test_laktationen.laktende, b_milch_hms_diagnose.diagnose
FROM            test_laktationen INNER JOIN
                         b_milch_hms_diagnose ON test_laktationen.lom = b_milch_hms_diagnose.lom AND b_milch_hms_diagnose.behanddatum BETWEEN 
                         test_laktationen.laktanfang AND test_laktationen.laktende INNER JOIN
                         b_milch_hms_kalbung ON test_laktationen.lom = b_milch_hms_kalbung.lom AND test_laktationen.laktanfang = b_milch_hms_kalbung.kalbedatum
WHERE        (b_milch_hms_diagnose.diagnose LIKE '6.01.01.%' OR
                         b_milch_hms_diagnose.diagnose LIKE '6.01.02.%' OR
                         b_milch_hms_diagnose.diagnose LIKE '6.01.03.%' OR
                         b_milch_hms_diagnose.diagnose LIKE '6.01.04.%') AND (b_milch_hms_kalbung.gebverlauf = 3 OR
                         b_milch_hms_kalbung.gebverlauf = 4)

This works like it should, but now I have to make this request from data tables. Is this possible with LINQ? What would be good practice to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:10:42+00:00Added an answer on June 14, 2026 at 10:10 pm

    You would need a data context to perform direct access. I would recommend Linq2Sql classes file (*.dbml) to get it started. Once you create your data structure in the Linq2Sql class with the server explorer, your linq statement would look something like:

    var context = new MyLinq2SqlContext();
    
    var results = (from lak in context.test_laktationen
        join milch in context.b_milch_hms_diagnose
            on lak.lom equals milch.lom
        join kalbung in context.b_milch_hms_kalbung 
            on lak.lom equals kalbung.lom and lak.laktanfang equals kalbung.kalbedatum
        where 
            (milch.diagnose.StartsWith("6.01.01") ||
            milch.diagnose.StartsWith("6.01.02") ||
            milch.diagnose.StartsWith("6.01.03") ||
            milch.diagnose.StartsWith("6.01.04")) &&
           (kalbung.gebverlaug == 3 || kalbung.geberlauf == 4) &&
           ((milch.behanddatum > lak.laktanfang && milch.behanddatum < lak.laktende) ||     (milch.behanddatum < lak.laktanfang && milch.behanddatum > lak.laktende))
        select new {
                lak.lom, 
                lak.laktanfang,
                lak.laktende,
                milch.diagnose
        }).Distinct();
    

    This will probably require tweaking in the final “where” clause to make sure you get the “between” portion correct. BETWEEN doesn’t translate natively into from Linq, but it can be coded in as long as you can predict which value is likely to be greater.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some queries that look like this: public List<AnObjectModel> GetObjectFromDB(TheParameters) { using MyDataContext
I have some pages that make PDO queries using prepare() and execute() (binding some
I'm using the VS2010 DataSet designer to make some select queries with optional parameters
I have created some documents and managed to make some simple queries but I
I have bat-file, that make some operations. How to run this file from Delphi
I have to read a text file and based on some logic, make some
I have a huge pl/sql stored procedure, where we make some deletions as long
I have been looking at making the switch from SQL TableAdapters to Linq using
I want to add some rows to a database using Linq to SQL, but
I have a web application that uses linq-to-sql queries (will soon be upgraded to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.