I have to leave in a DataTable only records with dates currently not present in the database.
So I read all existing dates using the stored procedure (is it correct?):
SELECT DISTINCT CAST(S.[date] AS DATE) -- original date is DATETIME2(0)
FROM ...
WHERE ...
and load it to a DataTable:
var tableDate = new DataTable();
new SqlDataAdapter(command).Fill(tableDate);
How to remove now from another table all unnecessary rows? I think LINQ could help but I’m not sure how..
I’m looking at your answer, which you say works, and you just want to know how to do it in a “single LINQ query.” Keep in mind that these queries all have deferred execution, so the following two queries are functionally equivalent:
And:
The second version is a lot harder to read, but nevertheless, it is “one query.”
Having said this, none of these examples really seem to match your question title, which suggests that you are trying to remove duplicate rows. If that is indeed what you are trying to do, here is a method that will do that:
If you don’t care about which duplicates removed then you can just remove the
OrderByline. You can test this as follows:(just replace “date” with “Code” in the
RemoveDuplicatesmethod for this example)Hopefully one of these answers your question. Otherwise I think you’re going to have to be more clear with your requirements.