I'm wondering what the 'best practice' is, when asking an event handler to unsubscribe its self after firing once.
For context, this is my situation. A user is logged in, and is in a ready state to handle work items. They receive a work item, process it, then go back to ready again. At this point, they may want to say they're not avail...
I want to build a Lambda Expression using Linq Expressions that is able to access an item in a 'property bag' style Dictionary using a String index. I am using .Net 4.
static void TestDictionaryAccess()
{
ParameterExpression valueBag = Expression.Parameter(typeof(Dictionary<string, object>), "valueBag");
Paramet...
Hi I have a query as -
var query=from e in DataContext.Employees
join d in DataContext.Dept
on e.DeptId equals d.Id
join o in DataContext.OtherInfo
on e.Id equals o.EmployeeId
where e.EmployeeId==4
select new Employee_Dept//DTO
{
EmployeeName=e.Name,...
I am trying to order a list of products based on the zindex property of the cross reference table with the category table (in this case called 'Chassis'), but I get the following error:
Cannot order by type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
The following is the method I am using:
public IQueryable<E_Product> Pr...
Hi All,
For the 1st example given on site: View-Site, my understanding is that normal order evaluates to [6;1;1] and applicative order evaluates to [6;2;2]
Can anyone please confirm my assessment?
Regards,
darkie
...
I'm looking to 'generalise' some code in a .NET 3.5 MVC application and have stumbled into a problem.
Background
I have a SomeController class with some actions:
public ActionResult Renew(string qualification, int tierId) { ... }
public ActionResult Reinstate(string qualification, int tierId) { ... }
public ActionResult Withdraw(strin...
from x in myCollection
group x by x.Id into y
select new {
Id = y.Key,
Quantity = y.Sum(x => x.Quantity)
};
How would you write the above as a lambda expression? I'm stuck on the group into part.
...
I wrote a method which calls a method that returns a linq query.
Inside this method, I need to apply a case expression to the linq query I'm receiving from the method I call. I thought that maybe with a lambda expression it would be possible to apply a case expression, but how can I do this?
...
So here is some code that simplifies what I've been working on:
vars = {
'a':'alice',
'b':'bob',
}
cnames = ['charlie', 'cindy']
commands = []
for c in cnames:
kwargs = dict(vars)
kwargs['c'] = c
print kwargs
commands.append(lambda:a_function(**kwargs))
print commands
def a_function(a=None, b=None, c=None):
...
(Not really sure if I phrased the question correctly...)
I want to create a lambda expression that would take an Object, attempt to convert it to a passed-in Type, and print to the console whether it was successful or not.
At a glance, the lambda expression may seem a pretty silly way to accomplish this task, but I'd really like to kno...
Elaboration of what I want to achieve :
I have an collection of an object in my itemsource.Suppose there are three items in my itemsource and i want each property of every single item to be assigned to different textboxes, how can i get this ?
textbox1.text = // assign the first value of an item to this
textbox2.text = // assign the s...
Not sure if this is possible, but here is what I am trying to do:
I want to have a dictionary that contains a mapping of a column index to a property name used to populate that index.
In my code I will loop through an array if strings and use the dictionary to look up which column it should map to.
My end result code would look like:
...
I get the error :
A local variable named 's' cannot be
declared in this scope because it
would give a different meaning to 's',
which is already used in a 'child'
scope to denote something else.
static void Main(string[] args)
{
string s = "hello"; // Line 1
var test = new[] { "abd", "def" }.Select(s => s.StartsWith...
I have the following class:
public class MyClass<T> where T : class
{
public void Method1<TResult>(T obj, Expression<Func<T, TResult>> expression)
{
//Do some work here...
}
public void Method2<TResult>(T obj, Expression<Func<T, TResult>> expression1, Expression<Func<T, TResult>>...
Example:
myObject.Stub(s => s.MyMethod(null)).IgnoreArguments().Return("bleh");
var s = "s";
A variable "s" is defined in a lambda and another variable "s" as a local variable within the same method. Visual Studio tells me "A conflicting variable is defined below" when I hover over the first "s". Why are these conflicting; the "s" in...
Hi,
i have a namespace string like "Company.Product.Sub1.Sub2.IService".
The Sub1/Sub2 can differ in their count, but normally their is one part which matches to
a Dictionary with AssemblyFullname as key and path to it as value.
Now ive written this code
string fullName = interfaceCodeElement.FullName;
var fullNamePart...
I have a list of types defined as:
typedef boost::mpl::list<Apple, Pear, Brick> OriginalList;
I would like to create a second list that does not contain any fruit, i.e. the resultant list formed from the first list would contain a single type Brick. Fruit is identified through a static const variable defined within the types, e.g.:
s...
With the following data
string[] data = { "a", "a", "b" };
I'd very much like to find duplicates and get this result:
a
I tried the following code
var a = data.Distinct().ToList();
var b = a.Except(a).ToList();
obviously this didn't work, I can see what is happening above but I'm not sure how to fix it.
...
Hi,
I'm working through the MVC Music Store in Visual Basic (mvcmusicstore.codeplex.com), trying to convert things as I go. I'm heving trouble with some of the lambda expressions in the Views, however. Specifically, on page 53 when the Album editor template is used, I am not seeing my editor template when I use the following code:
Orig...
I'm trying to use a nested multi-line lambda Function in VB.NET and am getting an error. Here's what my code looks like:
cartItems = cartItems.Select(Function(ci) New With {.CartItem = ci, .Discount = discountItems.FirstOrDefault(Function(di) di.SKU = ci.SKU)})
.Select(Function(k)
If k.Discount Is Not Nothing Then
...