nullable

Is there a nullable datepicker that I can bind to?

I am looking for a datepicker like what microsoft provides, but it doesn't support null values, and since this is tied to a nullable field on a database that isn't acceptable. I found this one, but according to the comments at the bottom of the page it has issues with binding to a database. I also have one in my project that I inherited...

ASP.Net - Strange behavior of nullable types in Application_EndRequest

I am using Global.asax to perform logging at the end of each request via the Application_EndRequest event. However, I am seeing some odd behavior of certain values stored in the HTTPContext.Current.Items collection. Below is the debug output for a nullable Enum. You can see that there is a value, but HasValue resolved to False?! {Syst...

ADO.NET Madness and Nullable Types

I've seem to have gone down a rabbit hole. I would like to convert the data from ADO .NET datasets into a Nullable type. At first I assumed that a straight cast (int?) would do it. How naive I was. Wrong, badly wrong. Now I'm trying to write a generic converter but am getting hung up on the syntax. This is so 2005 - someone must have sol...

Alternatives to nullable types in C#

I am writing algorithms that work on series of numeric data, where sometimes, a value in the series needs to be null. However, because this application is performance critical, I have avoided the use of nullable types. I have perf tested the algorithms to specifically compare the performance of using nullable types vs non-nullable type...

Nullable Int Column in DataSet

I'm working with .NET strongly-typed datasets and have a table with a nullable int column (and a nullable DateTime column as well). Apparently there is a bug with the dataset designer that prevents having nullable columns on these data types. The designer only allows "throw exception" as the default behavior for null values. Unfortuna...

Convert to a Nullable<T> from a string using Reflection

How can I convert TO a Nullable from a String using reflection? I have the following code to convert TO almost any value type given almost any value. There is quite a bit of code above this to use the IsAssignableFrom, etc. so this is the last resort. MethodInfo parse = t.GetMethod("Parse", new Type[] { typeof(string) }); if (parse ...

Report Server - unable to display correct input parameter via Iif() or Switch()

I have a nullable boolean input parameter with the following expression in my textbox: =iif(Parameters!Sorted.Value="","All",iif(Parameters!Sorted.Value="True","Sorted","Unsorted")) and I am trying to display this based on the value of Sorted input parameter Null = "All" True = "Sorted" False = "Unsorted" I have also tried the fol...

TimeSpan using a nullable date

How can i subtract 2 dates when one of them is nullable? public static int NumberOfWeeksOnPlan(User user) { DateTime? planStartDate = user.PlanStartDate; // user.PlanStartDate is: DateTime? TimeSpan weeksOnPlanSpan; if (planStartDate.HasValue) weeksOnPlanSpan = DateTime.Now.Subtract(planStartDate); // This line is ...

Automatic properties and Nullable types - are they incompatible?

I have a custom type with a nullable property that I am trying to project into from a nullable column in SQL. I am always getting a 'missingmethodexception' like so: {"Method not found: 'Void MyType.set_Number(System.Nullable`1<Int32>)'."} Is there a problem with trying to project into a custom type with nullable automatic properties?...

Nullable parameter values in MSBuild

I'm writing an MSBuild task to upgrade a database (full source here) and encountered an error/by design feature I don't know how to deal with. Basically, if I declare: public int? TargetVersion { [DebuggerStepThrough] get { return targetVersion; } [DebuggerStepThrough] set { targetVersion = value; } } and then attempt ...

Returning nullable string types

So I have something like this public string? SessionValue(string key) { if (HttpContext.Current.Session[key].ToString() == null || HttpContext.Current.Session[key].ToString() == "") return null; return HttpContext.Current.Session[key].ToString(); } which doesn't compile. How do I return a nullable string type? ...

Nullable value types

If a value type is declared nullable, how should I take precautions for this? I.e. if in the constructor I have: public Point3 ( Point3 source ) { this.X = source.X; this.Y = source.Y; this.Z = source.Z; } would it fail, if source was null? ...

Bind nullable DateTime to MaskedTextBox

I have a masked text box bound to a nullabe datetime, but when the date is blanked out, the validation on the masked text box won't complete. Is there a way to force this behaviour? I want a blanked out text box to equal a null DateTime. When the textbox is already null, the validation works. It only breaks when there is a date alrea...

How to present the nullable primitive type int in Java?

I am designing an entity class which has a field named "documentYear", which might have unsigned integer values such as 1999, 2006, etc. Meanwhile, this field might also be "unknown", that is, not sure which year the document is created. Therefore, a nullable int type as in C# will be well suited. However, Java does not have a nullable ...

svcutil.exe - Proxy generated not allowing for nullable fields

I am trying to consume a web service specified using WSDL by creating a WCF proxy using svcutil.exe, but the WSDL specifies that some of the operations have parameters that are optional (minOccurs="0"), for example: <xs:element minOccurs="0" maxOccurs="1" name="meetingId" type="xs:int" /> Unfortunately, the generated proxy does not al...

Nullable<> as TModel for ViewPage

What are the possible reasons what Nullable<> types are disallowed to be passed as TModel parameter of System.Web.Mvc.ViewPage<TModel> generic? This could be handy sometimes. In ASP.NET MVC source defined what TModel should be a class: public class ViewPage<TModel> : ViewPage where TModel : class but Nullable types are value types. M...

What is the reason not all value types are nullable?

Is there any penalty, such that you should only set them as nullable when you really need it? Thanks ...

Should I use a nullable int when working with int object IDs?

If I'm working with, say, a BookID of type int in my code that corresponds to an int primary key field in a database table (I'm using C# and SQL Server)... is it best practice, when I'm passing around IDs in my code, to use a nullable int and check for null to see if the BookID exists: if (BookID != null) { or, is it a better practice...

Is there an option to make Entity Framework revert empty strings to null?

Hi I am using an ADO.NET Entity-Framework ObjectContext to access my data store. I want the if values are set with empty strings, they should automatically become null. ...

Retrieve a list containing NULLS with Linq

Is it possible to use LINQ to retrieve a list that may contain nulls. For example if I have a left outer join like so: var query= from c in db.Customers join o in db.Orders on c.CustomerID equals o.CustomerID into sr from x in sr.DefaultIfEmpty() select x.OrderId; Ho...