I have an object with a DateTime field, ExpireDate, that is nullable and I'm using the DAL2 Repository Save function to save the data but when the DateTime field is Null, I get an "Object reference not set to an instance of an object" error.
The DateTime field is nullable for the object.
The code for the save is:
var ctx = DataContext.Instance();
var repo = ctx.GetRepository<MyObject>();
if (obj.ItemID >= 0)
repo.Update(obj);
else
repo.Insert(obj);
The code for the object is:
[Cacheable("Articles", CacheItemPriority.Default, 20)]
[TableName("MyObject")]
[PrimaryKey("ItemID", AutoIncrement = true)]
[Scope("ModuleId")]
public partial class MyObject
{
public int ItemID { get; set; }
public int PortalID { get; set; }
public int UserID { get; set; }
public DateTime CreatedDate { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime PublishDate { get; set; }
public DateTime? ExpireDate { get; set; }
public DateTime LastModifiedDate { get; set; }
}
The ExpireDate field is the field that causes the issues. What do I need to do to handle a null DateTime.