DataSet does not support System.Nullable in Export
try with dt.Columns.Add(pi.Name, Nullable.GetUnderlyingType( pi.PropertyType) ?? pi.PropertyType);
try with dt.Columns.Add(pi.Name, Nullable.GetUnderlyingType( pi.PropertyType) ?? pi.PropertyType);
If it’s null, it will hit the default label. public enum YesNo { Yes, No, } public class Program { public static void Main(string[] args) { YesNo? value = null; switch (value) { case YesNo.Yes: Console.WriteLine(“Yes”); break; case YesNo.No: Console.WriteLine(“No”); break; default: Console.WriteLine(“default”); break; } } } The program will print default. Unless null is … Read more
Lifted operators are operators which work over nullable types by “lifting” the operators which already exist on the non-nullable form. So for example, if you do: int? x = 10; int? y = 10; int? z = x + y; That “+” operator is lifted. It doesn’t actually exist on Nullable<int> but the C# compiler … Read more
Not in the language, no, but you can make your own: public struct Optional<T> { public bool HasValue { get; private set; } private T value; public T Value { get { if (HasValue) return value; else throw new InvalidOperationException(); } } public Optional(T value) { this.value = value; HasValue = true; } public static … Read more
Because string type’s null really points to nothing, there isn’t any object in memory.But int? type(nullable) even with value set to null still points to some object.If you read Jeffrey Richter’s “CLR via C#” you’ll find out that nullable type are just facade classes for common types with some incapsulated logics in order to make … Read more
Using the call method, you can achieve what you want with: nullableFunctionInstance?.call(blah) There’s also the apply method if you want to pass arguments.
You want to use the nullable form of Sum, so try casting your value to a nullable: from i in Db.Items select new VotedItem { ItemId = i.ItemId, Points = (from v in Db.Votes where b.ItemId == v.ItemId select v.Points).Sum(r => (decimal?) r.Points) } Your issue is discussed here in more detail: http://weblogs.asp.net/zeeshanhirani/archive/2008/07/15/applying-aggregates-to-empty-collections-causes-exception-in-linq-to-sql.aspx
C# supports “lifted” operators, so if the type (bool? in this case) is known at compile you should just be able to use: return x != y; If you need generics, then EqualityComparer<T>.Default is your friend: return !EqualityComparer<T>.Default.Equals(x,y); Note, however, that both of these approaches use the “null == null” approach (contrast to ANSI SQL). … Read more
You could retrieve that from sys.columns: select is_nullable from sys.columns where object_id = object_id(‘Schema.TheTable’) and name=”TheColumn”
Since DateTime is a struct, not a class, you get a DateTime object, not a reference, when you declare a field or variable of that type. And, in the same way as an int cannot be null, so this DateTime object can never be null, because it’s not a reference. Adding the question mark turns … Read more