nullable

How to query by embedded example containing null values using hibernate?

I have a problem with a query using hibernate. The entity class EntityClass has an embedded property embedded of type EmbeddedClass and this property has a nullable property optional. When all properties are set, i can do a very simpel HQL query as: Query query = getSession().createQuery( "FROM EntityClass t WHERE t.embedded = :embe...

Set a Nullable value type property via reflection

I'm attempting to map values of properties (via reflection) between different objects. This appears to be failing oddly on nullable value types. The following code: destProperty.SetValue(destObject, sourceProperty.GetValue(sourceObject, null), null); sets destProperty to null if destProperty is a nullable value type, despite sourcePr...

Is there any difference between using .GetValueOrDefault(0) and If(variable, 0) with nullable types?

Is there any difference between the 2 methods below for calculating c ... specifically boxing/unboxing issues? Dim a As Integer? = 10 Dim b As Integer? = Nothing Dim c As Integer ' Method 1 c = If(a, 0) + If(b, 0) ' Method 2 c = a.GetValueOrDefault(0) + b.GetValueOrDefault(0) ...

How to serialize Nullable<bool> ?

I want to serialize a nullable bool simply by converting it to a string public static string SerializeNullableBoolean(bool? b) { if (b == null) { return "null or -1 or .."; // What to return here? } else { return b.ToString(); } } What is the most appr...

Overloading Controller Actions

Hi Guys I was a bit surprised a few minutes ago when I tried to overload an Action in one of my Controllers I had public ActionResult Get() { return PartialView(/*return all things*/); } I added public ActionResult Get(int id) { return PartialView(/*return 1 thing*/); } .... and all of a sudden neither were working I f...

LINQ-to-SQL IN/Contains() for Nullable<T>

I want to generate this SQL statement in LINQ: select * from Foo where Value in ( 1, 2, 3 ) The tricky bit seems to be that Value is a column that allows nulls. The equivalent LINQ code would seem to be: IEnumerable<Foo> foos = MyDataContext.Foos; IEnumerable<int> values = GetMyValues(); var myFoos = from foo in foos wh...

Nullable ToString()

I see everywhere constructions like: int? myVar = null; string test = myVar.HasValue ? myVar.Value.ToString() : string.Empty; Why not use simply: string test = myVar.ToString(); Isn't that exactly the same ? At least Reflector says that: public override string ToString() { if (!this.HasValue) { return ""; } retur...

Why doesn't the conditional operator correctly allow the use of "null" for assignment to nullable types?

Possible Duplicates: Nullable types and the ternary operator. Why wont this work? Conditional operator assignment with nullable<value> types? This will not compile, stating "Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTime' and ''" task.ActualEndDate = Text...

Is it possible to create a generic Util Function to be used in Eval Page

I am currently binding a Nullable bit column to a listview control. When you declare a list view item I need to handle the case when the null value is used instead of just true or false. <asp:Checkbox ID="Chk1" runat="server" Checked='<%# HandleNullableBool(Eval("IsUsed")) %>' /> Then in the page I add a HandleNullableBool() func...

WPF Toolkit: Nullable object must have a value

Hi All, I am trying to create some line charts from a dataset and getting an error (WPF+WPF Toolkit + C#): Nullable object must have a value Here is a code that I use to add some data points to the chart: ObservableCollection points = new ObservableCollection(); foreach (DataRow dr in dc.Tables[0].Rows) { points.Add(new Vel...

How to pass null for a parameter in stored procedure - the parameter is uniqueidentifier

In C# code I have a variable Guid? name.But,how to initialize this parameter to null,since I cannot assign null for a guid type ...

Nullable datetime value from DatePicker

This is the case. I get the date from DatePicker control: DateTime current = datePicker1.SelectedDate; And I get an error: Cannot implicitly convert DateTime? to DateTime. So I guess it's up to a nullable type DateTime?. Is it safe to cast this type to a type I need like this: if (datePicker1.SelectedDate == null) current= DateT...

Why is django admin not accepting Nullable foreign keys?

Here is a simplified version of one of my models: class ImportRule(models.Model): feed = models.ForeignKey(Feed) name = models.CharField(max_length=255) feed_provider_category = models.ForeignKey(FeedProviderCategory, null=True) target_subcategories = models.ManyToManyField(Subcategory) This class manages a rule for importing ...

Liqn to sql null-able value in query

I need get all items these have no categories int? categoryId = null; var items=db.Items.Where(x=>x.CategoryId==categoryId); this code generate in where: where CategoryId=null instead of where CategoryId is null ok, when i write var items=db.Items.Where(x=>x.CategoryId==null); in my sql profiler it works: where CategoryId i...

how are nullable types implemented under the hood in .net?

In our own Jon Skeet's C# in depth, he discusses the 3 ways to simulate a 'null' for value types: Magic value (e.g. earliest possible DateTime is taken to be 'null') Reference type wrapper boolean flag It is mentioned that nullable types use the third method. How exactly do nullable types work under the hood? ...

NHibernate IUserType convert nullable DateTime to DB not-null value

I have legacy DB that store dates that means no-date as 9999-21-31, The column Till_Date is of type DateTime not-null="true". in the application i want to build persisted class that represent no-date as null, So i used nullable DateTime in C# //public DateTime? TillDate {get; set; } I created IUserType that knows to convert the entity ...

Binding a nullable int to an asp:TextBox

I have a property int? MyProperty as a member in my datasource (ObjectDataSource). Can I bind this to a TextBox, like <asp:TextBox ID="MyTextBox" runat="server" Text='<%# Bind("MyProperty") %>' /> Basically I want to get a null value displayed as blank "" in the TextBox, and a number as a number. If the TextBox is blank MyProperty sha...

Nullable values in C++

I'm creating a database access layer in native C++, and I'm looking at ways to support NULL values. Here is what I have so far: class CNullValue { public: static CNullValue Null() { static CNullValue nv; return nv; } }; template<class T> class CNullableT { public: CNullableT(CNullValue &v) : m_Value(T(...

How to deserialize null array to null in c#?

Here is my class: public class Command { [XmlArray(IsNullable = true)] public List<Parameter> To { get; set; } } When I serialize an object of this class: var s = new XmlSerializer(typeof(Command)); s.Serialize(Console.Out, new Command()); it prints as expected (xml header and default MS namespaces are omitted): <Command><To...

LINQ to SQL - Nullable<int> ForeignKey = An attempt was made to remove a relationship between...?!

Hi. I have a data model like this: [Table(Name = "DayWorks")] public class DayWork { [Column(DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)] public int ID { get; set; } ... /* no any EntitySet here for extensionable model purposes (really need) */ } [Table(Name = "Documents")] public class Document { ...