Can I Do a Foreach on a TimeSpan by Timespan Type?
By : Chavan Uttam Kiran
Date : March 29 2020, 07:55 AM
With these it helps A Timespan is a length of time, not a pair of Dates - I think there's confusion here. The Timespan represents "1 month" in this case, not a particular month (like 2010-04-01 to 2010-04-31). To do what you're looking for, you'd need something like this (Psuedo-code): code :
Get the number of months between start and end of contract range
For each month in that list
determine start and end of that month
Do your calculations(start, end)
next month
|
Using Expression.Call with Queryable.Select with a type known only at runtime
By : Frank Becker
Date : March 29 2020, 07:55 AM
it fixes the issue I am trying to select a column from an IEnumerable collection that has a type known only to me at runtime. The only way I can think of using this is using LINQ expressions to build a dynamic call to Queryable.Select. However, I'm having a lot of trouble figuring out the proper syntax to accomplish this. code :
var propertyType = typeof (string);
var propertyName = "Length";
IEnumerable list = new ArrayList { "one", "two", "three" };
var item = Expression.Parameter(typeof(object), "x");
var cast = Expression.Convert(item, propertyType);
var propertyValue = Expression.PropertyOrField(cast, propertyName);
var propertyValueAsObject = Expression.Convert(propertyValue, typeof (object));
var selectLambda = Expression.Lambda<Func<object, object>>(propertyValueAsObject, item);
list.Cast<object>().AsQueryable().Select(selectLambda);
|
Why Does This Queryable.Where Call Change the Queryable's Type Parameter?
By : Raoüf Wolvawab
Date : March 29 2020, 07:55 AM
Hope this helps Code to Reproduce Issue , Why does this happen? code :
using System;
public interface IWrapper<out T>
{
T Value { get; }
}
public class Wrapper<T> : IWrapper<T>
{
private readonly T value;
public Wrapper(T value)
{
this.value = value;
}
public T Value { get { return value; } }
}
class Program
{
static void Main(string[] args)
{
IWrapper<string> original = new Wrapper<string>("foo");
IWrapper<object> original2 = original;
IWrapper<object> rewrapped = Rewrap(original2);
Console.WriteLine(original2.GetType()); // Wrapper<string>
Console.WriteLine(rewrapped.GetType()); // Wrapper<object>
}
static IWrapper<T> Rewrap<T>(IWrapper<T> wrapper)
{
return new Wrapper<T>(wrapper.Value);
}
}
dynamic copy = ...;
Expression<Func<ChildQueryElement, bool>> filter = qe1 => true;
// Can't call an extension method "on" dynamic; call it statically instead
copy = Queryable.Where(copy, filter);
|
What is the correct SQL type to store a .Net Timespan with values < 00:00:00? i.e. negative timespan to sql server st
By : Alexander_Wu
Date : March 29 2020, 07:55 AM
around this issue As suggested by @Damien_The_Unbeliever in comment , adding this in answer. SQL Server doesn't have a data type that represents time spans you have to use integral type, measured in whatever units you need for appropriate resolution, e.g. seconds or milliseconds, etc.
|
Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable
By : user1932289
Date : March 29 2020, 07:55 AM
help you fix your problem You don't have an import for System.Linq, which means the compiler can't find LINQ to Objects, which is the LINQ implementation you're trying to use. Just add this to your imports: code :
Imports System.Linq
|