I have entity A which has an IList of B called Bs and B has an IList of C called Cs.
I want to search for all A's which have at least 5 C's in them. So I went and wrote
using (var s = this._sessionFactory.OpenSession())
{
IQueryable<A> q = s.Linq<A>();
// some code...
if (range.Min.HasValue)
q = ...
I have a LINQ Query that creates a new type that contains a days of week and a sum of hours worked.
My current (incorrect query) looks like this:
var resultSet = (from a in events
group a by a.Start.DayOfWeek into g
select new DaySummary
{
day = g.Key.ToString(),
...
I hear a lot about performance problems about lazy loading, no matter if at NHibernate, Linq....
The problem is N+1 selects. Example, I want all posts and its users, at foreach I lazy Load Users, them I need one select for posts, plus N select for each user.
Lazy Loading:
1 - select ....from post
N - select ....from user
The "good" ap...
Book List
XSLT Programmers Reference
Michael Kay
from the given Xml document,I want to iterate all <blist:books> elements.
(i.e)
How to i handle the namespace ?
i tried
XNamespace blist = XNamespace.Get("http://www.wrox.com/books/xml");
XElement element = XElement.Load("Books....
Apologies for the poor question title - I'm not sure how to describe what I'm doing but that is the best I could come up with, please edit it if what I'm asking for has a real name!
I have Programmes, which can have a group of Projects assigned, which in turn have groups of Outputs assigned.
I would like to get all the outputs for the ...
I am trying to grab some role information, the first node however does not have an element "projectRoleType" I want to skip over that one and only grab the ones that have a "projectRoleType" and "categoryId". Every way I try to check I always get the error: Object reference not set to an instance of an object. What am I not doing?
var...
Ok, so I'm iterating a collection. for each member that meets some criteria, I want to call a method on that member:
Here's how I'm doing it now:
foreach(MyObject obj in myCollection)
{
if(obj.Property == theSearchValue)
obj.DoIt();
}
For what it's worth, I think that the foreach is the most readable, clear way to do this (...
I'm using LINQ to Entities.
I have a table called Student; it has ID and Name as it's columns. ID is a primary key.
I'd like to be able select the name of the Student and get the amount of Students with the same Name.
So for example I'd have this as my table data.
ID Name
1 Bob
2 Will
3 Bob
After performing the query I'd r...
What Linq expression would I use to select the 1rst overloaded method that accepts a single string parameter?
For example to return the DateTime.ToString(string format) instead of the DateTime.ToString(IFormatProvider provider).
t = typeof(DateTime);
string[] validMethods = { "ToString" };
return t.GetMethods().Where(a => validMethods....
var subset = from item in document.Descendants("Id")
where item.Value == itemId.ToString()
select new PurchaseItem() {
Id = int.Parse(item.Parent.Element("Id").Value),
Name = item.Parent.Element("Name").Value,
Description = item.Parent.Element("Description").Val...
Hello, I have a LINQ query as follows
m_FOO = rawcollection.Select(p=> p.Split(' ')).Select(p =>
{
int thing = 0;
try
{
thing = CalculationThatCanFail(p[1]);
}
catch{}
return new { Test = p[0], FooThing = th...
I am trying to use LINQ to Nhibernate to get a count on a table in my database. However, the code I am running is pulling back all of the records in the table versus running select count() from table.
Here's my code-
public int GetTotalCount(Func<T, bool> where) {
IQueryable<T> queryable = this._sessionManager.GetCurrentS...
Hello =)
I want to make my queries better but have been un-able to find a resource out there which lays out when a query is shipped of to the db.
DBContext db = new DBContext();
Order _order = (from o in db
where o.OrderID == "qwerty-asdf-xcvb"
select o).FirstOrDefault();
String _custName = _order.Custo...
List<HelprClass.Organizer> org =
( from EventOrg in cntx.EventOrganizer
from MstrOrg in cntx.Organizer
where EventOrg.OrganizerID == MstrOrg.OrganizerID
Select new HelprClass.Organizer
{
OrganizerName = MstrOrg.OrganizerName
}).ToList()
This work fine now i want to use IN Opeartor in the above Query.
in t...
Hi,
I have a database containing users and roles. The table Users has a reference to the table roles as each user is bind to a role (one and only one).
When I use linq to retrieve the users, the field "role" shows in a datagrid as an integer (which is the primary key of the table Roles). However, I'd like to replace the field Role of the...
Here is a snippet of my (VB) LINQ:
From event_evn In xmlEvents.Descendants("event_evn") _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id") Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value E...
On a LINQ-result you like this:
var result = from x in Items select x;
List<T> list = result.ToList<T>();
However, the ToList<T> is Really Slow, does it make the list mutable and therefore the conversion is slow?
In most cases I can manage to just have my IEnumerable or as Paralell.DistinctQuery but now I want to bind the items to a...
Say I have a list List<MyObject> myObjectList. The MyObject object has a property named Order which is of type int. How can I determine whether two or more objects in myObjectList have the same Order using LINQ-to-objects?
...
Using LINQ, when calling several deleteOnSubmit in a row then calling SubmitChanges:
DataContext.DeleteOnSubmit(itemFromTb1);
DataContext.DeleteOnSubmit(itemFromTb2);
DataContext.SubmitChanges();
Will they always be deleted in the order (itemFromTb1 then itemFromTb2) I called them or not necessarily?
Edit:
I know the SubmitChanges()...
I have the following linq code.
searchResults = (from item1 in searchResults
join item2 in coll
on item1.skuID equals item2.Skuid
where item2.SearchableValue == value
select item1).ToList();
The variable searchResults is passed in the method as a generic List. The linq segment ab...