Current filter:
                                You should refresh the page.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Mohammed,

                                In general, when a key property contains a null value is abnormal and unacceptable for the application. Many features will not work at all or will operate with limitations. That said, I can recommend you a choice of the following solutions:

                                1. Revise your database data and make corrections, if needed;
                                2. Consider making a composite key for your persistent class to decrease the probability of an empty key: Task-Based Help > How To: Map a Persistent Class to a Database View Which Has No Key Field
                                3. Consider using Non-Persistent Objects with an artificial unique key. Populate them with data from your database view manually using ADO.NET or XPO means.
                                4. Handle the DevExpress.ExpressApp.SystemModule > ListViewProcessCurrentObjectController > CustomProcessSelectedItem  and other suitable events depending on your business tasks to prevent a standard operation over a corrupted record with an empty key to display a more user friendly message or provide another handling that meets your business needs.

                                If these solutions do not help you overcome your issue, send us a small debuggable sample with your latest implementations along with a database back or SQL view declaration code.

                                • Farooq 01.16.2017

                                  Hi Dennis.

                                  I have created a UniqueID in a view using the below View code and the View is working fine on the database side. But then i mapped this XAF and i get an error saying the Oid is a NonPersisten Key. Below are the codes sinppets of my View and XPO View Object

                                  SQL View with Randomly generated GUID

                                  [SQL]
                                  SELECT NEWID() as Oid,TransactionDate, Item, UnitCost, UOM, QtyIn, QtyOut, Warehouse, Project, SalesOrder, PurchaseOrder FROM dbo.ViewMaterialIn UNION SELECT NEWID() as Oid,TransactionDate, Item, UnitCost, UOM, QtyIn, QtyOut, Warehouse, Project, SalesOrder, PurchaseOrder FROM dbo.ViewMaterialOut

                                  XPOLite BO

                                  [VB.NET]
                                  Imports Microsoft.VisualBasic Imports System Imports System.Linq Imports System.Text Imports DevExpress.Xpo Imports DevExpress.ExpressApp Imports System.ComponentModel Imports DevExpress.ExpressApp.DC Imports DevExpress.Data.Filtering Imports DevExpress.Persistent.Base Imports System.Collections.Generic Imports DevExpress.ExpressApp.Model Imports DevExpress.Persistent.BaseImpl Imports DevExpress.Persistent.Validation Imports DevExpress.ExpressApp.ConditionalAppearance <ImageName("Inventory")> _ <DefaultClassOptions(), CreatableItem(False), NavigationItem("Inventory")> _ Public Class ViewProjectInventory Inherits XPLiteObject Friend Sub New(ByVal session As Session) MyBase.New(session) End Sub Public Key As ProjectInventoryViewKey <Key, Persistent, Browsable(False)> _ Public ReadOnly Property Oid As Guid Get Return Key.Oid End Get End Property <Persistent> _ Public ReadOnly Property TransactionDate() As Date Get Return Key.TransactionDate End Get End Property <Persistent> _ Public ReadOnly Property Item() As ItemMaster Get Return Key.Item End Get End Property <Persistent> _ Public ReadOnly Property UnitCost() As Decimal Get Return Key.UnitCost End Get End Property <Persistent> _ Public ReadOnly Property UOM() As UOM Get Return Key.UOM End Get End Property <Persistent> _ Public ReadOnly Property QtyIn() As Single Get Return Key.QtyIn End Get End Property <Persistent> _ Public ReadOnly Property QtyOut() As Single Get Return Key.QtyOut End Get End Property <NonPersistent> _ Public ReadOnly Property QtyBalance() As Single Get Return (QtyIn - QtyOut) End Get End Property <Persistent> _ Public ReadOnly Property Warehouse() As Warehouse Get Return Key.Warehouse End Get End Property <Persistent> _ Public ReadOnly Property Project() As Projects Get Return Key.Project End Get End Property <Persistent> _ Public ReadOnly Property SalesOrder() As SalesOrder Get Return Key.SalesOrder End Get End Property <Persistent> _ Public ReadOnly Property PurchaseOrder() As PurchaseOrder Get Return Key.PurchaseOrder End Get End Property End Class Public Structure ProjectInventoryViewKey <Persistent("Oid"), Browsable(False)> _ Public Oid As Guid <Persistent("TransactionDate"), Browsable(False)> _ Public TransactionDate As Date <Persistent("Item"), Browsable(False)> _ Public Item As ItemMaster <Persistent("UnitCost"), Browsable(False)> _ Public UnitCost As Decimal <Persistent("UOM"), Browsable(False)> _ Public UOM As UOM <Persistent("QtyIn"), Browsable(False)> _ Public QtyIn As Single <Persistent("QtyOut"), Browsable(False)> _ Public QtyOut As Single <Persistent("Warehouse"), Browsable(False)> _ Public Warehouse As Warehouse <Persistent("Project"), Browsable(False)> _ Public Project As Projects <Persistent("SalesOrder"), Browsable(False)> _ Public SalesOrder As SalesOrder <Persistent("PurchaseOrder"), Browsable(False)> _ Public PurchaseOrder As PurchaseOrder End Structure
                                • Dennis (DevExpress) 01.17.2017

                                  Hello Mohammed,

                                  The current issue is that in your custom code the essential attributes are applied to a wrong class member.
                                  You must either declare a public field exactly as in the Task-Based Help > How To: Map a Persistent Class to a Database View Which Has No Key Field  article OR a writeable public property (with a setter and getter), as shown in the How to create a persistent object for a database table with a compound key article.

                                • Farooq 01.17.2017

                                  Hi Dennnis,

                                  Following your reference articles i have got clarity on the cause of the issue an d tackled it by having a unique Oid in the view itself and this time i used a permanent GUID field and adjusted the mapping of the class. It is working now without any errors. Thanks for your guidance and support.

                                  Public Class ViewProjectInventory
                                      Inherits XPLiteObject

                                      Friend Sub New(ByVal session As Session)
                                          MyBase.New(session)
                                      End Sub

                                      <Key, Persistent, Browsable(False)> _
                                      Public Key As ProjectInventoryViewKey

                                      <Persistent("TransactionDate")> _
                                      Public TransactionDate As Date
                                      <Persistent("Item")> _
                                      Public Item As ItemMaster
                                      <Persistent("UnitCost")> _
                                      Public UnitCost As Decimal
                                      <Persistent("UOM")> _
                                      Public UOM As UOM
                                      <Persistent("QtyIn")> _
                                      Public QtyIn As Single
                                      <Persistent("QtyOut")> _
                                      Public QtyOut As Single
                                      <Persistent("Warehouse")> _
                                      Public Warehouse As Warehouse
                                      <Persistent("Project")> _
                                      Public Project As Projects
                                      <Persistent("SalesOrder")> _
                                      Public SalesOrder As SalesOrder
                                      <Persistent("PurchaseOrder")> _
                                      Public PurchaseOrder As PurchaseOrder
                                  End Class

                                  Public Structure ProjectInventoryViewKey
                                      <Persistent("Oid"), Browsable(False)> _
                                      Public Oid As Guid
                                  End Structure

                                • Dennis (DevExpress) 01.17.2017

                                  You're always welcome!