Hey all,
Hoping somebody can shed some light, and perhaps a possible solution to this issue I'm having...
I have used LINQ to SQL to pull some data from a database into local entities. They are products from a shopping cart system. A product can contain a collection of KitGroups (which are stored in an EntitySet (System.Data.Linq.Ent...
I have been using these common EntityObjectFilters as a "pipes and filters" way to query from a collection a particular item with an ID:
public static class EntityObjectFilters
{
public static T WithID<T>(this IQueryable<T> qry,
int ID) where T : IEntityObject
{
return qry.SingleOrDefault<T>(item => item.ID == ID)...
There are a couple of posts about this on Stack Overflow but none with an answer that seem to fix the problem in my current situation.
I have a page with a table in it, each row has a number of text fields and a dropdown. All the dropdowns need to use the same SelectList data so I have set it up as follows:
Controller
ViewData["Submar...
I want a method to update certain entries of an IEnumerable. I found that doing a foreach over the entries and updating the values failed as in the background I was cloning the collection. This was because my IEnumerable was backed by some LINQ->SQL queries.
By changing the method to take a List I have changed this behavior, Lists are a...
I need an easy way to iterate over multiple collections without actually merging them, and I couldn't find anything built into .NET that looks like it does that. It feels like this should be a somewhat common situation. I don't want to reinvent the wheel. Is there anything built in that does something like this:
public class MultiCol...
I'm trying to do cast a List to an IEnumerable, so I can verify that different lists are not null or empty:
Suppose myList is a List < T > . Then in the caller code I wanted:
Validator.VerifyNotNullOrEmpty(myList as IEnumerable<object>,
@"myList",
@"Clas...
I am using a Telerik GridView, and having an issue trying to sort a column that is made of of a List<>. In this forum entry, the Telerik team states that the grid can sort IComparable and group/filter IEquatable<> no matter of the Silverlight version. In the xaml below, you will see the four columns that I have in my grid. The SVOs co...
I know that technically, an Interface is used for reading and not writting or editing however, I want to add an add and addrange function to the following class, here is what I currently have which is not working
public class HrefCollection : IEnumerable<Href>
{
private IEnumerable<Href> hrefs;
public IEnumerable<Href> Add( Hr...
Recently I came across a situation where set theory and set math fit what I was doing to the letter (granted there was an easier way to accomplish what I needed - i.e. LINQ - but I didn't think of that at the time). However I didn't know of any generic set libraries. Granted IEnumerables provide some set operations (Union, etc.), but not...
I have two collections a and b. I would like to compute the set of items in either a or b, but not in both (a logical exclusive or). With LINQ, I can come up with this:
IEnumerable<T> Delta<T>(IEnumerable<T> a, IEnumerable<T> b)
{
return a.Except (b).Union (b.Except (a));
}
I wonder if there are other more efficient or more compac...
Hi,
I have IEnumerable which contains number Data inside it.
Edit
The IEnumerable is from System.Collection.Ienumerable directive.
Attached the snapShot of Viual Studio, Enum that Contains Data:
Just to brief about the above image, eLevelData is the IEnumerable variable, in which I have my data .
Now I want to go to the data at in...
In the simplified example, there are 2 Regular Expressions, one case sensitive, the other not. The idea would be to efficiently create an IEnumerable collection (see "combined" below) combining the results.
string test = "abcABC";
string regex = "(?<grpa>a)|(?<grpb>b)|(?<grpc>c)]";
Regex regNoCase = new Regex(regex, RegexOptions.Ignore...
I have a method which returns an IEnumerable<> which it builds up using the yield return syntax:
namespace Validation
{
public class UserValidator
{
public IEnumerable<ValidationError> Validate(User user)
{
if (String.IsNullOrEmpty(user.Name))
{
yield return new ValidationE...
Possible Duplicate:
C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived>
I have D1 and D2 which derive from B. When i write var ls = (IEnumerable<B>)(cond?lsD1:lsD2); I get a runtime cast error. IIRC this is a well known problem. My question is
1) Is this allowed yet? perhaps in .NET 4? I have 2010 but my project ...
Not long time before I've discovered, that new dynamic keyword doesn't work well with the C#'s foreach statement:
using System;
sealed class Foo {
public struct FooEnumerator {
int value;
public bool MoveNext() { return true; }
public int Current { get { return value++; } }
}
public FooEnumerator Ge...
I often have to implement some interfaces such as IEnumerable<T> in my code.
Each time, when implementing automatically, I encounter the following:
public IEnumerator<T> GetEnumerator() {
// Code here...
}
public IEnumerator GetEnumerator1() {
// Code here...
}
Though I have to implement both GetEnumerator() methods, they im...
Sorry for being lazy but where's IEnumerable.OrderBy declared. I know it's an extension method but where, in which class is it declared?
PS: Opening reflector...
...
In .NET 3.5 List<> gains a ForEach method. I notice this does not exist on IList<> or IEnumerable<> what was the thinking here? Is there another way to do this? Nice and simple short way to do this?
I ask because I was at a talk where the speaker said always use the more general interfaces.
But why would I use IList<> as a return type i...
I do something like this and the value in the collection doesn't change
[Test]
public void EnumerableTest()
{
var source = GetFoos();
source.First().One = "hello";
Assert.AreEqual(source.First().One, "hello");
//it fails
...
I'd like to write:
IEnumerable<Car> cars;
cars.Find(car => car.Color == "Blue")
Can I accomplish this with extension methods? The following fails because it recursively calls itself rather than calling IList.Find().
public static T Find<T>(this IEnumerable<T> list, Predicate<PermitSummary> match)
{
return list.ToList().Find(match...