Hi, so here's the code with irrelevant bits left out:
public IEnumerable<T> GetByQuery(Expression<Func<T, bool>> filter
{
try
{
return Session.Linq<T>().Where(filter);
}
catch(Exception ex)
{
// custom exception handling here
}
finally
{
CloseSession();
}
return null;
}
...
Hi,
Can anyone tell me if the following query calls the database multiple times or just once?
var bizItems = new
{
items = (
from bl in db.rc_BusinessLocations
orderby bl.rc_BusinessProfiles.BusinessName
select new BusinessLocationItem
{
BusinessLocation = bl,
BusinessProfile ...
I need some LINQ advice (or even general advice) on how to implement the following:
Basically, I have 3 entities: Projects -- EmployeeProjects -- Employees (1 to Many and Many to 1 relationship, respectively), i.e. an employee could be assigned to many Projects and a Project could have many Employees and all our housed in EmployeeProjec...
This is sort of the next step of the LINQ to DB2 question I asked here.
Following zb_z's answer, I poked around a bit with the code for DB_Linq and have managed to add working DB2 support. (It's still in its infancy now, not ready to be contributed back to the project yet.) The proof of concept worked great, it was pretty exciting act...
i have the following code which doesnt seem to be working:
Context:
I have two lists of objects:
* listOne has 100 records
* listTwo has 70 records
many of them have the same Id property (in both lists);
var listOneOnlyItems = listOne.Except(listTwo, new ItemComparer ());
here is the comparer
public class ItemComparer : IEqualit...
I'm new to Linq and SQL terminology - can someone tell me why this isn't working (syntax is not right - I can't compare u.UserID int with an Enumerable)
var projectUsers = from u in SimpleRepository.All<User>()
where u.UserID == (from i in SimpleRepository.All<ProjectUser>()
where...
I have a Generic collection of Student in StudentCollection Class and each Student Class is having a SubjectCollection Class.
I have a method which returns the StudentCollection.How can I get the SubjectCollection directly from the StudentCollection ?
I found two ways of doing it---
First Way
StudentSubjectCollect...
Hi, can someone please tell me or point me in the right direction regarding how to save a LINQ table to an excel spreadsheet?
Thanks!
Mr Cricket
...
XElement xml = new XElement("MyMenu",
from c in db.Security_Module_Menus
//where (c.ParentID == 0)
orderby c.Menu_ID
select new XElement("Item",
new XAttribute("Text", c.Menu_Name), new XAttribute("NavigateUrl", c.Target_UR...
I thought I'd seen somewhere a while back an example of where clause which called a function that gave a bool result ,and I can't find it again so I'll outline my problem.
I have a collection
Dictionary< string, KeyValuePair < int, int >>
in which I want to have a query for the string key. On the surface that is simple but unfo...
I am new to Linq, though I was thinking of making use of LINQ expressions to query within the collections of my business objects.
We have created a new hierarchical set of models with several properties. Some properties have a List<classx>. Would I be able to change the type to IQueryable<classx>? But then how would I add a new instanc...
how to order descending an IEnumerable<T> with linq or lambda ?
...
I have two table Company and Employee. And there relation is Company(one) - Employee(many).
And I want to concatenate all the Employees' name to a string and output.
I know I can write such a query :
String names = "";
foreach(var emp in Company.Employee)
{
names += emp.name;
}
But If I use this mean, I would l...
Hi,
(Code below has been updated and worked properly)
There is dynamic OrderBy sample from LinqPad. What I want to do is just simply apply 'Where' rather than 'OrderBy' for this sample. Here is my code:
IQueryable query =
from p in Purchases
//where p.Price > 100
select p;
string propToWhere = "Price";
P...
Given this code:
int min = 0;
Expression<Func<List<IUser>, bool>> ulContainsJohn =
(l => l.Where(u => u.FirstName == "John").Count() > min);
Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
min = 3;
Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
The...
What would be the best way to set a gridView.DataSource for LINQ query with some foreign keys and get fields in the parent tables? Like this:
The table BOOK have a Author_Id, which is related to table Author
class:
public IQueryable<Book> ListAll()
{
RENDBDataContext db = new RENDBDataContext();
var result = from b in db.Books...
Say I have a class:
public class theclass
{
public string a;
public string b;
public string c;
}
Yes. It's a bad class. Moving on. Say I have a 100 value array of this class. Is there a quick way with linq to get a list of strings with all of the values of b for the contents of the array?
...
I'm trying to pull out the Roles below into an IEnumerable<KeyValuePair<int, string>>
<PROJECT PROJECT_NO="161917">
<CONTACT CLIENT_ID="030423253272735482765C" CONTACT_NO="1">
<ROLE ROLE_ID="2" ROLE_DESC="ARCHITECT" />
<ROLE ROLE_ID="5" ROLE_DESC="INTEGRATOR" />
</CONTACT>
</PROJECT>
private static ProjectContact Buil...
Hi,
How can insert an item to Expression array? For example: some code like
Expression<Func<int, bool>>[] exprs;
Expression<Func<int, bool>> expr = i => i > 0;
exprs.Add(expr);
Thanks
...
I have a large unsorted list of items. Some items are important and need to listed first, followed by unimportant items. The items should be sorted by name in the two groups. I have a solution, but I believe it can be optimized. First, it gets a list of important items. Then a list of everything else, then concatenates the results. ...