Page 1 of 2

Issue with Nullable<DateTime>

Posted: Mon May 02, 2011 3:03 am
by euregon
Hi,

we noticed an issue with Nullable:

Code: Select all


public class Data
{
      public Nullable MyTime { get; set; }
}

List mydata = new List();

mydata.Add(new Data(){ MyTime=null });
mydata.Add(new Data(){ MyTime=DateTime.Now });

report.RegData("mydata", mydata);

mydata arrives in the designer as "datetime".

We expected "datetime(Nullable)".

It's possible to manually set the type to "datetime(Nullable)",
however after reloading the Designer the type changes
back to "datetime".

We are using "Stimulsoft Reports.Ultimate 2011.1 Trial"
on Win7/Ultimate/64 - VS2010 - Prof.



Issue with Nullable<DateTime>

Posted: Mon May 02, 2011 7:17 am
by Ivan
Hello,

The RegData() method convert all data to dataset and pass him to the report.
DataSet do not support nullable types.
So please try to use the RegBusinessObject() method.

Thank you.

Issue with Nullable<DateTime>

Posted: Mon May 02, 2011 8:08 am
by euregon
Thank you!

Issue with Nullable<DateTime>

Posted: Mon May 02, 2011 12:55 pm
by Andrew
We are always glad to help you.

Thank you.

Issue with Nullable<DateTime>

Posted: Wed May 04, 2011 7:25 am
by euregon
Hi Andrew,

I tried the RegBusinessObject method and I have two questions:

How far is this article still valid? http://forum.stimulsoft.com/Default.aspx?g=posts&t=451
RegBusinessObject is/was removed?

I tried to use RegBusinessObject and I ran into some issues.

1) We use grouping in our Report. Using the same grouping condition I now get
several invalid cast exception in the report render messages.

2) We used subreports for the child items. When using the RegBusinessObject
method the dependency to the main Databand isn't working. I had to remove
the Subreports and put them on the Main report.

So back to my original question - is there another way to use Nullable types?

When setting using Regdata and setting the type to datetime(nullable) everything
works as expected!

Thank you.



Issue with Nullable<DateTime>

Posted: Thu May 05, 2011 7:45 am
by Andrew
Hello,
How far is this article still valid? http://forum.stimulsoft.com/Default.aspx?g=posts&t=451
RegBusinessObject is/was removed?
It was long time ago.
It was the first, unsuccessful attempt to implement the work with business objects. Those methods have been removed.
Since that time there were lots of changes in the product. On the current moment, for working with business objects a completely different algorithm was created.
I tried to use RegBusinessObject and I ran into some issues.
1) We use grouping in our Report. Using the same grouping condition I now get
several invalid cast exception in the report render messages.
Can you please send us a simple test project, which reproduces the issue?
2) We used subreports for the child items. When using the RegBusinessObject
method the dependency to the main Databand isn't working. I had to remove
the Subreports and put them on the Main report.
When working with business objects, there are limitations due to the great complexity of their implementation:
- sorting is not implemented;
- it is impossible to use relations.

Accordingly, master-detail bands should be placed in one page/in one container.
So back to my original question - is there another way to use Nullable types?

When setting using Regdata and setting the type to datetime(nullable) everything
works as expected!
But every time after synchronization of the dictionary, the column type is changed on datetime.

Please tell us what problems do you have if not to establish the nullable type?

Thank you.

Issue with Nullable<DateTime>

Posted: Fri May 06, 2011 6:42 am
by euregon
Hello Andrew
Andrew wrote:
Please tell us what problems do you have if not to establish the nullable type?
we are using Microsoft Entity Framework 4.0 for generating the POCO objects
with the data for the report.

E.F. 4.0 will automaticually create the following code

Code: Select all

    public partial class V_ReportingStuff
    {
        #region Primitive Properties
        public virtual Nullable Birthday
        {
            get;
            set;
        } 
        #endregion
    }
Within the report i want to display the Birthday if the value is not null.
Thats very simple. But i can't change the data of the autogenerated
class, because we have NULL values in our database.

I achieved this now with a deep copy constructor and a
wrapper property.

Code: Select all

    public partial class V_ReportingStuffExtended : V_ReportingStuff
    {
        public V_ReportingStuffExtended (V_ReportingStuff r)
        {
            //...
        }

        public DateTime Birthday_NotNullWrapper
        {
            get { if (Birthday.HasValue) return Birthday.Value; return DateTime.MinValue; }
            set { Birthday = value; }
        }
    }
I like the RegData() way, because it much simpler then the RegBusinessObject() method!




Issue with Nullable<DateTime>

Posted: Tue May 10, 2011 12:44 am
by Alex K.
Hello,

Please send us sample project with your sample data for analysis.

Thank you.

Issue with Nullable<DateTime>

Posted: Tue May 10, 2011 9:19 am
by euregon
Hello Aleksey,

i created a small example displaying the issue.

We have a simple class:

Code: Select all

        public class DummyData
        {
            public string Name { get; set; }
            
            public virtual Nullable Birthday
            {
                get;
                set;
            }
        }
Within the Report on DataBand1 I have a BeforePrint event trigger:

Code: Select all

	if( !MyData.Birthday.HasValue )
        {
           // do something
        }
However i get a runtime error, because the MyData.Birthday is a
datetime and no datetime(nullable). If you change the datatype to
datetime(nullable) everything is fine.

I tried casting to and object and recasting it back to a Nullable
but still the same runtime error.

I created a workaround with the NotNullWrapper as in my first post

Code: Select all

	if( MyData.Birthday_NotNullWrapper == DateTime.MinValue )
        {
           // do something
        }
but this requires deep copying the content of the class, because the class
code is autogenerated by the entity framework.


-- edit -- :

I checked the Report File - so nullables are possible - but they aren't detected
properly:

Code: Select all

      
        MyData
        
          Name,System.String
          Birthday,System.DateTime
          Birthday_NotNullWrapper,System.DateTime
          _ID,System.Int32
          _Current,System.Object
        
        
        MyData
        MyData
      
vs.

Code: Select all

      
        MyData
        
          Name,System.String
          Birthday,System.Nullable`1[System.DateTime]
          Birthday_NotNullWrapper,System.DateTime
          _ID,System.Int32
          _Current,System.Object
        
        
        MyData
        MyData
      




Issue with Nullable<DateTime>

Posted: Thu May 12, 2011 7:39 am
by Alex K.
Hello,

As a way, in this case you can use the following code:

Code: Select all

if ( MyData["Birthday"] == DBNull.Value )
instead

Code: Select all

if( !MyData.Birthday.HasValue )
Thank you.