Branching references issue

Mar 22, 2013 at 4:28 PM
Can't say how much easier this ORM has made my life. Chris Tacke is a personal hero.

Being lazy I was curious if anyone had luck with the following.

I have a table that has a OneToOne(OneToMany in OpenNetCF.oRM) reference and the subsequent table has many references.

Code throws a null reference exception from the DoInsertReferences method in SQL StoreBase. (Stack trace below)

I have things working by doing insert(topLevelObject) then insert(midLevelObject,true), so it isn't a big deal if I need to continue doing so.
    public partial class Form1 : Form
    {
        SqlCeDataStore db = new SqlCeDataStore(@"\temp\db.sdf");
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            if (!db.StoreExists)
            {
                db.CreateOrUpdateStore();
            }

            db.AddType<ThinyInstallationLocal>();
            db.AddType<UniversalWorkOrderDataLocal>();
            db.AddType<WidgetLocal>();
            db.AddType<InstalledEquipmentLocal>();
            db.AddType<WorkOrderImageLocal>();
        }

        private void uiButton1_Click(object sender, Resco.UIElements.UIMouseEventArgs e)
        {
            var collector = new ThingyInstallationLocal()
                {
                    AssetID = 5,
                    CommunicationChannel = "40",
                    CurrentView = "View",
                    LinePole = "30 pole",
                    SerialNumber = "12345678",
                    TransformerNumber = "400",
                };

            var wod = new UniversalWorkOrderDataLocal()
                {
                    WODID = -1,
                    WorkStart = DateTime.Now,
                    WorkEnd = DateTime.UtcNow,
                    //This is the foreign Key to the WorkOrder
                    WorkOrderID = 0,
                    WorkOrderNumber = "12345678",
                    Altitude = 0.0,
                    WorkOrderType = "FixyThing",
                    DeviceSerialNumber = "12345",
                    SerialNumber = "12345678",
                    ServiceType = "K",
                    GPSDate = DateTime.Now,
                    Latitude = 0.0,
                    Longitude = 0.0
                };

            var consumedMat = new WidgetLocal()
                {
                    MaterialTypeID = 1,
                    WidgetID = -1,
                    Waste = 5,
                    Quantity = 12,
                };

            var equipment = new InstalledEquipmentLocal()
                {
                    EquipID = -1,
                    AssetId = 5,
                    Auxiliary1 = "Aux1",
                    Auxiliary2 = "Aux2",
                    Auxiliary3 = "Aux3",
                    SecondarySerial = "12345679",
                    Serial = "12345678"
                };
            var image = new WorkOrderImageLocal()
                {
                    ImageID = -1,
                    Altitude = 0.0,
                    CreatedDate = DateTime.Now,
                    Description = "Image Taken",
                    FileName = "Image.jpg",
                    GPSDate = DateTime.Now,
                    ImageCode = "Code",
                    Latitude = 0.0,
                    Longitude = 0.0
                };

            wod.Widgets = new WidgetLocal[]{consumedMat};
            wod.InstalledEquipment = new InstalledEquipmentLocal[]{equipment};
            wod.Images = new WorkOrderImageLocal[]{image};
            collector.WorkOrderData = wod;


            //I want to do this, insert the top level object
            db.Insert(collector,true);

            //But I'm having to do this
            //db.Insert(collector);
            //db.Insert(wod,true);

            lblUpdate.Text = "Success";
        }
at OpenNETCF.ORM.SQLStoreBase1.DoInsertReferences(Object item, String entityName, KeyScheme keyScheme, Boolean beforeParentInsert)
at OpenNETCF.ORM.SqlCeDataStore.OnInsert(Object item, Boolean insertReferences)
at OpenNETCF.ORM.DataStore
1.Insert(Object item, Boolean insertReferences)
at App.Form1.uiButton1_Click(Object sender, UIMouseEventArgs e)
at Resco.UIElements.UIElement.OnClick(UIMouseEventArgs e)
at Resco.UIElements.Controls.UIElementControl.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Resco.UIElements.Internals.NativeMethods.CallWindowProcCE(IntPtr prevWndFunc, IntPtr hWnd, WM msg, Int32 wParam, Int32 lParam)
at Resco.UIElements.Internals.NativeMethods.CallWindowProc(IntPtr prevWndFunc, IntPtr hWnd, WM msg, Int32 wParam, Int32 lParam)
Coordinator
Mar 22, 2013 at 4:38 PM
If you can build up a simple example that repros it (3 entities and a database with some sample data) and send it to me it will make it way easier for me to test and diagnose.