Select N to N rows from database using LINQ [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a table with 30 rows, i want to fetch rows from 15-25 using LINQ, tried using Range operator but that is not working in my scenario.
any help appreciated.

You can use <your linq>.Skip(n).Take(m), which will take the values between n and m.

You can use Skip() and Take() for that:
var result = query.Skip(14).Take(11);
(But I'm not 100% sure your query provider can translate that correctly to sql).

Related

Is there a way to compare the exact value of a string in C# [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
So I made a simple c# file reader because I was bored and added an if statement to filter the results. But when I ran it, it gave me more results than I wanted. I was supposed to get
276, 2, and there was only one line inside the file with that value, but I got multiple. I checked the file and it had lines ending with the same value. I tried string.Equals(line, "276, 2") but it gave me the same results. I doubt there isn't something in c# that doesn't solve this issue.
You can use Regex, as it's mentioned in this issue
bool result = Regex.IsMatch(line, "\\b276, 2\\b");

using a function inside a lamba expression [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
To manage rounding there are usually two methods, the first method is round values then to sum them. Or sum values then to round them. Of course to the required precision that you want.
I want to go with the first method and I need to update this line that currently do the opposite.
this.ClonedEntity.MontantHT = ArroundDecimal.CustomDecimalArround(correctedLines.Sum(l => l.MontantHT ?? 0));
When I try to call my static method in the lambda expression it doesn't work.
How would you suggest to do it while keeping use of the linq syntax ?
Thank you.
You could try something like this:
this.ClonedEntity.MontantHT = correctedLines
.Select(x=>ArroundDecimal.CustomDecimalArround(x.MontantHT ?? 0))
.Sum();
something = correctedLines.Sum(l => ArroundDecimal.CustomDecimalArround(l.MontantHT ?? 0))

C# Regex that captures a percentage in a named group [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have the following regex pattern:
-?\d+(?:\.\d+)?%
Which works really well to match percentages. Now what I need is to be able to get the numerical value of this in a group.
I have tried the following:
(?<percentage>-?\d+(?:\.\d+)?)%
(?<percentage>-?\d+(\.\d+)?)%
(?<percentage>(-?\d+(?:\.\d+)?))%
(?<percentage>(-?\d+(\.\d+)?))%
None of them work and I only get the integer part of the percentile.
How can this be accomplished?
The correct regex is:
(?<percentage>-?(?:\d*\.?\d+|\d+\.?\d*))%
I tried the following examples and they all seemed to work (using the first regex that you tried):
Regex.Match("12%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12
Regex.Match("12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12.345
Regex.Match("-12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// -12.345
You might note the use of the "#" in front of the regular expression string - maybe that is the issue you are having.

Count items in MongoDB [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
How do I get a count of all items in a Mongo collection, using the 2.x C# driver?
I'm trying to use CountAsync, which I need to pass in a filter. I don't want to filter - I want everything returned.
You can always pass the empty document in the method like this
db.collection.CountDocumentsAsync(new BsonDocument());
db.collection.count()
In C# you can use Count() on the cursor of your collection.
Try as below:
var mongo = new Mongo();
mongo.Connect();
var db = mongo.GetDatabase("DatabaseName");
var collection = db.GetCollection<Product>();
var totalCount= collection.Count();
you can check in the following URL
this url

SQL- do not select those rows which contain specific text [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I cannot use Except keywords due to version problem. Anyone here know. How can i select all rows except not those rows which contain specific text.select all rows except those which contain specific text.I cannot use Except Keyword due to version problem in MS S.Q.L
select * from your_table
where some_column not like '%specific text%'
Select * from Table1
where EmpPU NOT Like '%CSE%'
AND EmpPU NOT Like '%ECE%'
AND EmpPU NOT Like '%EEE%'

Categories

Resources