Example #1
0
        private TDataObj _GetDataObject(EntityObject entity)
        {
            TDataObj obj = null;

            if (_owner.IsStored)
            {
                // Try to find data object through IWrapDataAccess.
                obj = DataObjectHelper.GetDataObject(entity) as TDataObj;

                if (obj == null)
                {
                    DataObjectContext ctx = ContextHelper.GetObjectContext(
                        _entityRef);

                    obj = DataObjectHelper.GetOrCreateDataObject <TDataObj>(ctx,
                                                                            entity);
                }
            }
            else
            {
                obj = DataObjectHelper.GetDataObject(entity) as TDataObj;
                if (obj == null)
                {
                    throw new DataException(Properties.Messages.Error_InvalidDataObjectInstance);
                }
            }

            return(obj);
        }
Example #2
0
        /// <summary>
        /// Gets or creates data object depending on whether entity object
        /// contains associated data object.
        /// </summary>
        /// <param name="context">DataObjectContext object.</param>
        /// <param name="entity">Entity object.</param>
        /// <returns>Generic data object.</returns>
        public static T GetOrCreateDataObject <T>(DataObjectContext context,
                                                  EntityObject entity)
            where T : DataObject
        {
            Debug.Assert(entity != null);

            // get associated data object
            IWrapDataAccess dataAccess = entity as IWrapDataAccess;

            if (dataAccess == null)
            {
                throw new DataException(Properties.Messages.Error_GetWrapDataObjectFailed);
            }

            T obj = GetDataObject(entity) as T;

            if (obj == null)
            {
                // associated object does not exist, create it
                obj = context.CreateObject <T>(entity);

                // associate object with entity
                dataAccess.DataObject = obj;
            }

            return(obj);
        }
 /// <summary>
 /// Creates a new instance of DataObjectCollection class.
 /// </summary>
 public DataObjectCollection(DataObjectContext context,
                             string entitySetName,
                             SpecFields specFields, bool isReadOnly)
 {
     _dataService = new DataService <TDataObject>(context, entitySetName,
                                                  specFields);
     _isReadOnly = isReadOnly;
 }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        internal DataObjectManager(DataObjectContext context, string entityName, SpecFields specFields)
        {
            _context = context;

            _dataService = new DataService <T>(context, entityName, specFields);
            _dataService.ContextCollectionChanged += new CollectionChangeEventHandler(
                _dataService_ContextCollectionChanged);
        }
Example #5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        internal ScheduleManager(DataObjectContext context, string entitySetName,
                                 SpecFields specFields,
                                 DataService <Route> routeDS)
            : base(context, entitySetName, specFields)
        {
            Debug.Assert(routeDS != null);
            _routeDS = routeDS;
        }
        public DataService(DataObjectContext context, string entitySetName,
                           SpecFields specFields)
            : base(context, entitySetName)
        {
            Debug.Assert(specFields != null);
            _specFields = specFields;

            context.ObjectStateManager.ObjectStateManagerChanged += new CollectionChangeEventHandler(
                ObjectStateManager_Changed);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of DataService class.
        /// </summary>
        protected BaseDataService(DataObjectContext context, string entitySetName)
        {
            Debug.Assert(context != null);
            Debug.Assert(entitySetName != null);

            _fullEntitySet = ContextHelper.GetFullEntitySetName(context,
                                                                entitySetName);

            _context   = context;
            _entitySet = entitySetName;
        }
        private void _RemoveObject(DataObject obj)
        {
            DataObjectContext ctx = null;

            if (GetObjectContext(out ctx))
            {
                ContextHelper.RemoveObject(ctx, obj);
            }
            else
            {
                obj.CanSave = false;
            }
        }
        protected bool GetObjectContext(out DataObjectContext context)
        {
            context = null;

            bool res = false;

            if (_owner.IsStored)
            {
                context = ContextHelper.GetObjectContext(_entities);
                res     = true;
            }

            return(res);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Opens SQL Server CE database using specified file path.
        /// Upgrades database if scheme version less than the current one.
        /// </summary>
        /// <param name="path">
        /// Database file path.
        /// </param>
        /// <returns>
        /// DataObjectContext object.
        /// </returns>
        public static DataObjectContext OpenDatabase(string path)
        {
            Debug.Assert(path != null);

            try
            {
                string sqlConnStr = DatabaseHelper.BuildSqlConnString(path, true);

                // upgrade database if necessary
                CheckForDbUpgrade(sqlConnStr);

                // create object context
                DataObjectContext ctx = new DataObjectContext(
                    _BuildEntityConnStr(sqlConnStr));

                // keep connection alive to ensure exclusive mode
                ctx.Connection.Open();

                return(ctx);
            }
            catch (Exception e)
            {
                Logger.Error(e);

                SqlCeException ceEx = _GetCEException(e);
                if (ceEx != null &&
                    ceEx.NativeError == SSCE_M_FILESHAREVIOLATION)
                {
                    throw new DataException(Properties.Messages.Error_DbFileSharingViolation,
                                            DataError.FileSharingViolation);
                }
                else
                {
                    throw;
                }
            }
        }
Example #11
0
 /// <summary>
 /// Creates a new instance of DataObjectOwnerCollection class.
 /// </summary>
 public DataObjectOwnerCollection(DataObjectContext context,
                                  string entitySetName,
                                  SpecFields specFields, bool isReadOnly) : base(context, entitySetName, specFields, isReadOnly)
 {
 }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        internal OrderManager(DataObjectContext context, string entityName, SpecFields specFields)
            : base(context, entityName, specFields)
        {
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the DeletionCheckingService class.
 /// </summary>
 /// <param name="dataContext">The reference to the data context to be used for accessing
 /// project data.</param>
 internal DeletionCheckingService(DataObjectContext dataContext)
 {
     Debug.Assert(dataContext != null);
     _dataContext = dataContext;
 }
Example #14
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public DataService(DataObjectContext context, string entitySetName)
            : base(context, entitySetName)
        {
            context.ObjectStateManager.ObjectStateManagerChanged += new CollectionChangeEventHandler(
                ObjectStateManager_Changed);
        }