As far as I can understand, the linq method FirstOrDefault() returns null if a record-set is empty. Why can't use the ?? operator against the function? Like so:
Double d = new Double[]{}.FirstOrDefault() ?? 0.0;
Update
I don't want to check if d is null later on in my code. And doing:
Double d new Double[]{}.FirstOrDefault() == nul...
Hello all.
I have the following code that pulls off a list of items used in an text box autocomplete extender:
return autocomplete.tblAutoCompletes
.Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
.OrderBy(p => p.ACItem)
.Select(p => p.ACItem)
...
Hey,
I can fix this problem by messing with outher parts of my codebase but I thought I'd ask to see if there is an easier way of doing this.
I've got the following linq query.
(select a in objectA
where a.type = 1
select new
{
Id = a.Id,
Field2 = <needThisValue>
Field3 = <needThisValue>
}).ToList();
Now the two "needTh...
hello,
please help me to figure out how to replace the loop below with a linq expression:
using System.Web.UI.WebControls;
...
Table table = ...;
BulletedList list = new BulletedList();
foreach (TableRow r in table.Rows)
{
list.Items.Add(new ListItem(r.ToString()));
}
this is a contrived example, in reality i am not going to co...
Hello all.
I have the following code that gives me a an array in an autocomplete extender:
return autocomplete.tblAutoCompletes
.Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
.OrderBy(p => p.ACItem)
.Select(p => p.ACItem)
...
No coffee. Brain. Not. Functioning.
I have this linq query here:
Public Function ListAllVisitDates() As List(Of SelectListItem)
Dim visitdates = db.SchoolVisitDates.Select(Function(t) New SelectListItem() With {.Text = t.VisitDate, .Value = t.VisitDateID}).ToList()
Return visitdates
End Function
It returns a long date of MM d...
I have a list of numbers, and I need to create every possible unique combination of the numbers in the list, without repeats, using a LINQ query. So, for example, if I have { 1, 2, 3 }, the combinations would be 1-2, 1-3, and 2-3.
I currently use two for loops, like so:
for (int i = 0; i < slotIds.Count; i++)
{
for (int j = i + 1; ...
I have a LINQ query I wish to run and drop the result into a var or IQueryable. However, I'm binding the result to multiple (4 to 10) controls and only want the query to run once.
When I just put the result into all the datasource values, the query runs for every control and the controls (comboboxes, for example), change selectedvalue...
Hi.
I am new to LINQ and am trying to sort this one out.
I am trying to grab records for multiple accounts (multiple account ids)
and sort the results according to the date.
What I have currently is putting the results in a list
such that multiple rows / account are contained in each list item.
This is close but not exactly what I...
Is it possible to write a query where we get all those characters that could be parsed into int from any given string?
For example we have a string like: "$%^DDFG 6 7 23 1"
Result must be "67231"
And even slight harder: Can we get only first three numbers?
...
Hi, I have a RadGrid that was working fine. I then added a CustomValidator which contains a LINQ. Now when you update the updates aren't shown immediately, the old data is there. You have to do a Refresh for the updated data to come through. I narrowed the problem down to a LINQ query in the CustomValidator. It goes something like this:
...
Hello,
I'm creating some kind of auction application, and I have to decide what is the most optimize way for this problem. I'm using BL Toolkit as my OR Mapper (It have nice Linq support) and ASP.NET MVC 2.
Background
I've got multiple Category objects that are created dynamically and that are saved in my database as a representatio...
I currently have a list of a book object as follows:
public class Book()
{
public int BookId { get; set; }
public string Name { get; set; }
public string Author { get; set; }
}
List<Book> books = BookRepository.SelectAll();
I would like to return a string list/array of Authors for return via a Json Result in my action met...
Help! My fingers are falling off from typing so much.
I have a lot of objects that have sane names to them. The Database names are not so sane, and i'm stuck defining my property names in all my projections.
For example:
from f in foo select new MyClass() {MyID = f.ID, MyName = f.f, MyTime = f.t}
Etc.. now, multiply this by hundr...
Hi everybody!
Please help me solve my big problem.
in my on-line shopping project i created a dynamic Category List (with Infinite Level Depth) Implemented in a Single Table in DB with Self join.
the schema is like below:
Update
I want to use a JQuery plugin to make a Multi Level Menu bar. this plugin uses <ul> and <li> elements so I sh...
All,
I've got the following code, and looking into ways to improve its readibility (and remove the null check) by using Linq.
var activePlan = CurrentPlans.First();
var activeObjectives = activePlan != null ? activePlan.Objectives : null;
The closest I get is the following:
var activeObjectives = CurrentPlans.Take(1).Select(x => x.O...
i get all column values from Users to StandardUsers id,Name,SurName and PostCount data to add. But Return below error:
IN " entityUsers.GetType().GetProperty(columnNames[i]).SetValue(entityUsers, columnValues[i], null);" Return To Me Error : Set method of characteristics not found.
public static class MyDynamicInsertCustomerExtension...
How can i change below codes to second Type: i try to use flexable codes like first =>second usage...
First Type
private void Form1_Load(object sender, EventArgs e)
{
List<City> cities = new List<City>
{
new City{ Name = "Sydney", Country = "Australia" },
new City{...
Can anybody tell the equivalent LINQ syntax for this query in c#?
SELECT Users.UserName, UserStatus.StatusTitle, UserStatus.StatusDetails
FROM UserStatus
INNER JOIN Users ON UserStatus.UserId = Users.UserID
where Users.userid=3
OR users.userID in (
SELECT UserFriends.FriendId
FROM Users
INNER JOIN UserFriends ON Users.Use...
class TimeObject
{
DateTime time;
bool isMatinee;
}
Given: {8:00, 9:30, 11:00, 12:10, 2:00, 4:00, 5:20} -- a collection of TimeObjects
Output: (8:00AM, 9:30, 11:00, 12:10PM, 2:00), 4:00, 5:20 -- return a string, oh and AM/PM should be picked up from localization strings
Caveats: AM/PM only shown for first time, ( ) encloses th...