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...
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 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)
...
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...
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...
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...
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...
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...
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...
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...
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
...
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...
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 ...
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...
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?
...
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 ...
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...
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(...
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...
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
{
...