Why Reflector ver 7 produced wrong Linq code like this [closed] - c#

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
private FileStorageFolder GetCapsuleContentFolder(FileStorageDataContext db)
{
IQueryable<FileStorageFolder> source = from dbFolder in db.FileStorageFolders
where (dbFolder.ParentID == null) && (dbFolder.Purpose == reportFolderPurpose)
select dbFolder into dbFolder
join dbSubFolder in db.FileStorageFolders on dbFolder.ID equals
dbSubFolder.ParentID into dbSubFolder
where (dbSubFolder.Purpose == capsulelayoutFolderPurpose) &&
(dbSubFolder.FolderName == capsuleReportContent)
select dbSubFolder;
Instrument.Assert(source.Count<FileStorageFolder>() == 1);
return source.Single<FileStorageFolder>();
}
this is not correct syntax.Does anyone know how to create IQueryable typed base on this?

If it is problematic, try cranking down the "Optimisation" setting to, say, .NET 2.0. This will then be forced to display the explicit .Select(...) etc. This should produce correct C#, but without the LINQ style.
Note, however, that it may also reverse the apparent call-order, since it will probably use explicit extension-method representation. The code should be equivalent either way, though.

Related

How to add a second condition in Linq Query [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I have this linq query in my controller and it is working fine,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers");
but I would like to add a second condition to the query to filter out the results,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus = 1);
Thanks for your help.
You made a typo, just need to use comparison operator (==) instead of assignation (=)
So it would be like that:
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus == 1);

Linq and String.Compare - the left hand side of an assignment must be a variable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to write the following LINQ query...
string userSearch = textBoxSearchUserInput.Text;
//LINQ query for Member name search
var MemberNameSearch =
from member in context.Members
where String.Compare(userSearch, member.MemberLastName, true) = 0
select member;
But I'm getting the error message in the title.
What I'm trying to achieve, comparing two strings while ignoring the case
Thanks
where String.Compare(userSearch, member.MemberLastName, true) == 0
To compare you need to use ==
This would work
String.Equals(userSearch, member.MemberLastName, StringComparison.OrdinalIgnoreCase)
You should change it
where String.Compare(userSearch, member.MemberLastName, true) = 0
To
where String.Compare(userSearch, member.MemberLastName, true) == 0

compare the month part with linq [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to compare the month part of two values in linq but im getting an error
property or indexer DateTime.Month cannot be assigned to
Here's the code
var item = model.Where(d => d.DATE2.Date.Month = dto.StartDate.Month).FirstOrDefault();
model is a list of objects with datetime properties and the dto.Startdate is also a datetime
You may not come up with this question if you read the error message carefully, since its clear enough. Anyway, you have to use == here for comparing two values, = is for assignment purpose(basic knowledge). After making this small change your query will look like the following:
var item = model.Where(d => d.DATE2.Date.Month == dto.StartDate.Month).FirstOrDefault();
You can make them even simple by using FirstOrDefault instead for Where as like this:
var item = model.FirstOrDefault(d => d.DATE2.Date.Month == dto.StartDate.Month);

How to see if two variables are not equal [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I knew that you can check if variables are equal with = or ==, but can you check if it is less than or greater that with < >, but is there a way to check if two variables are not equal, but instead diffrent
In most modern programming languages, this is accomplished with the use of the ! in front of the = sign as in !=
a != b (Used in C# and others)
Or
a <> b (Useful if your program is using additional languages)
and sometimes you use it like
NOT a == b (Again, useful if your program is calling another language that uses this form.)
Use the not equal to != operator?
if (a != b)
{
}

How to convert List<decimal> to List<string>? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My question is part of this problem:
I recieve a collection of id's from a form. I need to get the keys, convert them to string and pass it to the db.
using (var db = new DbAmsecEntities())
{
cashsafelist = (from safe in db.Cashsafes
where safe.StoreId == (decimal)Convert.ToInt64(ddlLocationLists.SelectedValue)
select safe.CashsafeId).ToList();
cashsafevalues = cashsafelist.Select(x => x.ToString).ToList();//getting error here
}
You need to use () in ToString
cashsafevalues = cashsafelist.Select(x => x.ToString()).ToList();
You can also use List.ConvertAll which was available since 2.0.
cashsafevalues = cashsafelist.ConvertAll<string>(d => d.ToString());
It can be more efficient than ToList because the list will be initialized with the correct size.

Categories

Resources