I need to access the current and previous element in an IQueryable object. If I had an int array, I would do the following:
var array = new int[]{0,1,2,3,4};
for(var i = 1; i<array.Length ; i++)
{
method1(array[i-1], array[i]);
}
I don't know to do the same with IQueryable, since it does not implement IList.
...
I'm building a LINQ query using a loop that appends predicates using an array:
foreach (string tag in tags)
{
result = result.Where(p => (p.TagsDelimited).Contains("," + tag + ","));
}
This creates all the necessary clauses, but each clause compares only the last element in the tags array, producing the sql
(((',' + [t0].[TagsDel...
So basically I have an application that works with just one user, but I'd like to make it multi-user. This would involve me logging a user in, and keeping the user ID in session, plus adding a user id column to my database tables. no biggy.
I'd like to change my dbml, or use it's partial, so that any query I throw through it also gets
...
I'm trying to find the next available Groupname on my project. I want the groupnames look like "Gruppe 1", "Gruppe 2" and so on. So that's what i got so far:
int i = 0;
while ((from GroupViewModel g in _groups
where g.GroupName == ("Gruppe " + (++i).ToString())
select g).Any());
Group group = new Group() { Name = string....
I want to populate a dropdown with values from database and constant hard-coded literals using linq. For example, assuming I already have northwind datacontext, i want to populate the dropdown with category table and some constants so that the dropdown will have something like below.
value text
0 [All]
-1 [None]
1 Beverages
2 Condiment...
I have a table with many values inside of it that might have single quotes around them. I need to create a duplicate table without those single quotes. I can't modify the original table as I need to use it, 'as-is' later.
I've done this with a table.Clone and using a foreach to loop through the rows and columns removing single quotes ...
This used to work for me and then it failed. I want to return only those items that contain all the filters, not at least one filter as it is doing now. WHat is wrong here?
private IQueryable<IndexItem> FilteredIndex (IQueryable<IndexItem> index, IEnumerable<string> filters)
{
var filteredIndex= from f in filters.AsQueryab...
I am having a problem giving a LINQ predicate the knowledge it needs to sort either alphabetically or numerically.
I am working with a multi-value pivoted set of data with has a sortable column. The column is always stored as varchar in the DB, however, it has lookup knowledge of what that data type actually is. To simplify, in additio...
List<int> a = 1,2,3
List<int> b = 2,4,5
output
1,3,4,5
...
List<int> a = 11,2,3,11,3,22,9,2
//output
11
...
We are working on a C# windows project with enterprise library 1.0 that needs to be updated to either LINQ or Entity framework. (.NET 3.5)
The application uses mainly SQL connections as stored procedures and XML files to store settings.
What is the pros and cons with
LINQ and Entity framework in this case?
Are the rumors true that LI...
With Linq To Sql - what is the best way to update the value of one table in a database when a value changes in a different table?
For example in TableA, there is a column called DateModified. TableA has an association to TableB. Now I want to set the value of the DateModified field to the current date every time the record changes in ta...
Hi,
How easy would it be to write a dumb LINQ provider that can just use my class definitions (which don't have any object references as properties) and give me the translated SQL. It can assume the name of the properties and the columns to be same as well as the names of the classes and the underlying tables. Can you please give me som...
I'm trying to learn some Linq to XML stuff, and I came across the XPathSelectElement function in XElement. This function seems to do just what I need, but for some reason, I can't use it! Check out my code:
XElement rootElement = XElement.Load(dataFile);
XElement parentElement = rootElement.XPathSelectElement(xPath);
...
So I've been using LINQ for a while, and I have a question.
I have a collection of objects. They fall into two categories based on their property values. I need to set a different property one way for one group, and one way for the other:
foreach(MyItem currentItem in myItemCollection)
{
if (currentItem.myProp == "CATEGORY_ONE"...
I have a method that alters an "Account" object based on the action delegate passed into it:
public static void AlterAccount(string AccountID, Action<Account> AccountAction) {
Account someAccount = accountRepository.GetAccount(AccountID);
AccountAction.Invoke(someAccount);
someAccount.Save();
}
This works as intended...
AlterAc...
I validate data for a table made in the linq designer in the event OnValidate.
This event is fired when I insert records, but not is fired when I update records.
I have this code:
public bool Save(int id, string marca, string modelo, string año, string motor,
bool disponible, RuleList issues)
{
Usado u;
if (id == 0)
{
...
I'm trying to find a LINQ oneliner that takes a Dictionary<String,Int> and returns a Dictionary<String,SomeEnum>....it might not be possible, but would be nice.
Any suggestions?
EDIT: ToDictionary() is the obvious choice, but have any of you actually tried it? On a Dictionary it doesn't work the same as on a Enumerable... You can't pas...
I want to remove an item from the result of a LINQ query before using it to databind. What is the proper way to do this?
The foreach in my illustration is the topic of my question. Illustration:
var obj =
(from a in dc.Activities
where a.Referrer != null
&& a.Referrer.Trim().Length > 12
&& a.Session.IP.NumProblems == 0...