nullable

C-like language without NULL?

Hi I was recently watching an old video about how null pointers were a billion dollar mistake. He points out both C# and java as they have run-time checks but don't completely eliminate it enough and this is somewhat understandable. He also points out the C at one point which he feels so sure of is a great problem. I get that null termin...

Having an issue with Nullable MySQL columns in SubSonic 3.0 templates

Looking at this line in the Settings.ttinclude string CheckNullable(Column col){ string result=""; if(col.IsNullable && col.SysType !="byte[]" && col.SysType !="string") result="?"; return result; } It describes how it determines if the column is nullable based on requirements and returns either "" or "?" to the ge...

Converting a Guid to Guid?

Is this an idiomatic way to convert a Guid to a Guid?? new Guid?(new Guid(myString)); ...

Nullable Type implementation without nullable feature of C#

How can we implement a nullable type in C# if we didn't have this feature in C#? ...

What is the use of Nullable<bool> type?

a bool variable could hold true or false, while bool? could be null as well. Why would we need a third value for bool ? If it is not true, what ever it is, it is == false Can you suggest a scenario where I would fancy a bool? instead. Thanks ...

Firebird SQL: Check if notNULL constraint is set for a specific column?

I want my C# program to know if the notNULL constraint is set for a specific Firebird database column. Can it be checked dynamically, perhaps by querying the meta data? I find the Firebird documentation to be very sparse. Also, how does Firebird provide information what columns exist in a specific table? ...

Nullable List<> as out parameter

Is this possible? private void Test(out List<ExampleClass>? ExClass) { } A nullable List<> that is also an out parameter? ...

How can I declare in C sharp a List with nullable double values?

The purpose is to enumerate the list and count how many nullable values I have, It will be used in order to test some Linq code because I lack of database. The thing is that no matter how I tried to define it I get from my compiler: "The type or namespace name List1' could not be found. Are you missing a using directive or an assembly ...

Casting (int?)null vs. new int?() - Which is better?

I use Nullable<T> types quite a lot when loading values into classes and structs when I need them to be nullable, such as loading a nullable value from a database (as the example below). Consider this snippet of code: public class InfoObject { public int? UserID { get; set; } } // Load the ID into an SqlInt32 SqlInt32 userID = rea...

in C# sharp, how you pronounce 'T?'

How do you pronounce 'bool?', 'int?' and their ilk? I've been mulling over options like "nullable of T", "T hook", "T huh", "T what" and "T" with a rising inflection. I'm not particularly satisfied with these as they seem either cumbersome or affected or both. ...

Linq OrderBy breaks with navigation property being null.

Working with four tables. Users -> has basic user info including a userid and a departmentid (int) Groups -> basic group info including a groupid GroupsMembers -> table that has the relationship between a group and it's members, many to many relationship, so groupid and userid are the columns Departments -> basic department info includi...

How can I stop nHibernate from helpfully setting a date value on a non-null object field when the underlying database field value is null?

I read with excitement the first article that popped up in google -- it was exactly my problem. I have an object model with a non-null date field, but the underlying database field was nullable, and had a null value. It was a DateTime. nHibernate set the value to .Net's Date.MinValue, then tried to save it back, yielding an error. Th...

Why is there a questionmark on the private variable definition?

I am reading an article about the MVVP Pattern and how to implement it with WPF. In the source code there are multiple lines where I cannot figure out what the question marks in it stand for. private DateTime? _value; What does the ? mean in the definition? I tried to find it in the help from VS but failed. ...

How to make a view column NOT NULL

I'm trying to create a view where I want a column to be only true or false. However, it seems that no matter what I do, SQL Server (2008) believes my bit column can somehow be null. I have a table called "Product" with the column "Status" which is INT, NULL. In a view, I want to return a row for each row in Product, with a BIT column se...

HQL nullable property should not be ignored, help?

Hey All, I have: Class Foo { String name; String value; Foo parent; //Foo.parent is OneToOne and nullable } I have the following HQL: FROM Foo f WHERE (lower(f.name) like concat( lower('string') , '%' )) or (lower(f.value) like concat( lower('string') , '%' )) or (lower(f.parent.name) like concat( lower('string') , '%' )) The que...

How does the NotNull trait work in 2.8 and does anyone actually use it?

trait NotNull {} I've been trying to see how this trait can guarantee that something is not null and I can't figure it out: def main(args: Array[String]) { val i = List(1, 2) foo(i) //(*) } def foo(a: Any) = println(a.hashCode) def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract def foo(a:...

How scala generic constraints to nullable types work

I've tried two ways to constrain a generic type parameter to a nullable type, but both seem to have some unexpected problems. First attempt (using T <: AnyRef): scala> def testAnyRefConstraint[T <: AnyRef](option:Option[T]):T = { | //without the cast, fails with compiler error: | // "found: Null(null) required: T" | o...

How to compare nullable types?

I have a few places where I need to compare 2 (nullable) values, to see if they're the same. I think there should be something in the framework to support this, but can't find anything, so instead have the following: public static bool IsDifferentTo(this bool? x, bool? y) { return (x.HasValue != y.HasValue) ? true : x.HasValue && x...

Is DBNull.Value required for nullable types as SqlCommandParameter.Value

Which approach is recommended: void Add(int? value) { command.Parameters.Add("@foo").Value = value; } or void Add(int? value) { command.Parameters.Add("@foo").Value = (object)value ?? DBNull.Value; } ...

Why use Nullable when the type can be assigned Null already?

I'm currently working with a library and noticed something weird when using functions I already made(where I must do casting). The library had a function defined like public DateTime? GetDate(){..} What is the point of this? Why not just make it a regular DateTime and return null as normal if there is some error getting the date? Am...