I wanted to deserialize an XML message containing an element that can be marked nil="true" into a class with a property of type int?. The only way I could get it to work was to write my own NullableInt type which implements IXmlSerializable. Is there a better way to do it?
I wrote up the full problem and the way I solved it on my blog.
...
Hi Everyone
Can someone explain to me why a nullable int cant be assigned the value of null e.g
int? accom = (accomStr == "noval" ? null : Convert.ToInt32(accomStr));
What's wrong with that code?
Thanks
...
First off, let me preface this question by stating that I'm really a pretty terrible data modeler. I know only enough to be dangerous.
The table I'm building has four foreign keys, two of which reference the same table. Here's the create statement for that table.
CREATE TABLE IF NOT EXISTS `abnr`.`reputation_event_log` (
`id` INT ...
Hi experts,
How do we assign null value to int column in LINQ.
eg.
SQLDBDataContext sqlD = new SQLDBDataContext();
var result = from p in sqlD.loadsRadius(Convert.ToInt32(Request["radius"]), .....
here if Request["radius"] is null gives an error.
I could pass 0 via this but I need to change in many already existing procedures.
Th...
Hi,
How do I check if a given object is nullable in other words how to implement the following method...
bool IsNullableValueType(object o)
{
...
}
EDIT: I am looking for nullable value types. I didn't have ref types in mind.
//Note: This is just a sample. The code has been simplified
//to fit in a post.
public class BoolCon...
I understand that boxing and unboxing is about casting (real type to object... object to real type). But I do not understand what the MSDN say about it with the Nullable. Here is the text I do not understand:
When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the Nullable object, no...
I'm currently using winforms databinding to wire up a data editing form. I'm using the netTiers framework through CodeSmith to generate my data objects. For database fields that allow nulls it creates nullable types. I've found that using winforms databinding the controls won't bind properly to nullable types.
I've seen solutions onl...
Hi all:
Just wondering if there is any best practice for DAL to represent null value (from a nullable column).
We currently have our own in-house DAL and are representing null value with int.MinValue. However, this rise concerns with developers thinking that when comparing values, we are purposely imposing another "added" value onto i...
C# 2.0 gives me access to nullable types. This seems very convenient when I want the DateTime variable in the database to be null. Is there anything I should worry about when using nullable types or can I go overboard and make every type I have nullable?
...
I get the following compilation error with the following source code:
Compilation Error:
Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'MyEnum'
Source Code
public enum MyEnum
{
Value1, Value2, Value3
}
public class MyClass
{
public MyClass() {}
public MyEnum? M...
I'm trying to create a relation where any of four different parts may be included, but any collection of the same parts should be handled as unique.
Example:
An assignment must have an assigned company, may optionally have an assigned location, workgroup and program.
An assignment may not have a workgroup without a location.
Let's assu...
This code compiles:
static void Main(string[] args)
{
bool? fred = true;
if (fred == true)
{
Console.WriteLine("fred is true");
}
else if (fred == false)
{
Console.WriteLine("fred is false");
}
else
{
Console.WriteLine("f...
If have this in the setter of a property:
decimal? temp = value as decimal?;
value = "90"
But after the cast, temp is null...
What is the proper way to do this cast?
...
The following code compiles:
class Testing<TKey, TValue>
{
public bool Test(TKey key)
{
return key == null;
}
}
However, TKey can be a value type, and possibly not allow the value "null".
I know the results of this program, and how to add constraints. What I'm wondering is why doesn't the compiler disallow this...
Is there anyway to have the var be of a nullable type?
This implicitly types i as an int, but what if I want a nullable int?
var i = 0;
Why not support this:
var? i = 0;
...
I know merely checking for whether the type is not a value type is not sufficient. How can i account for those Nullable?
DUPLICATE
http://stackoverflow.com/questions/374651/how-to-check-if-an-object-is-nullable
...
I've got an object that has a type property. When the type is set to Int64, and I try and pull the type info later, I get System.Nullable.
Here's the type Info
{Name = "Nullable`1" FullName = "System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0]]"}
How do I get to the System.Int64 type of this?
...
Hi,
I have a category table which has a foreign key to it self by a nullable parentId field. In Entity-Framework when a relation is created, the entity is generated without any relation fields. I mean, in my example when I created a parentId-Id relation in Category table, the generated Category Entity will have an int typed Id property ...
I have a Category entity which has a Nullable ParentId field. When the method below is executing and the categoryId is null, the result seems null however there are categories which has null ParentId value.
What is the problem in here, what am I missing?
public IEnumerable<ICategory> GetSubCategories(long? categoryId)
{
var subCate...
Two issues that will likely be immediately obvious, but I've spent too long already tracking them down:
I've set up an AuditInterceptor in order to do automatic auditing on entities that implement my IAuditable interface which is used as follows:
public class AuditInterceptor : EmptyInterceptor
{
public override bool OnSave(object...