Beispiel #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);
        }
 /// <summary>
 /// Retrieves data objects from the specified source.
 /// </summary>
 /// <typeparam name="T">The type of data objects to be retrieved.</typeparam>
 /// <typeparam name="TEntity">The type of source entities.</typeparam>
 /// <param name="source">The source of data objects to be retrieved.</param>
 /// <returns>A collection of data objects from the specified source.</returns>
 private IEnumerable <T> _FindObjects <T, TEntity>(IQueryable <TEntity> source)
     where T : DataObject
     where TEntity : EntityObject
 {
     foreach (var entity in source)
     {
         yield return(DataObjectHelper.GetOrCreateDataObject <T>(_context, entity));
     }
 }
        /// <summary>
        /// Retrieves data object by specified key name and object id.
        /// </summary>
        /// <param name="key">
        /// EntityKey object that represents entity id.
        /// </param>
        /// <returns>
        /// Generic data object. Null value is returned if the data object
        /// cannot be found.
        /// </returns>
        protected T FindObjectById <T>(EntityKey key)
            where T : DataObject
        {
            Debug.Assert(key != null);

            T obj = default(T);

            object entity = null;

            if (_context.TryGetObjectByKey(key, out entity))
            {
                obj = DataObjectHelper.GetOrCreateDataObject <T>(_context,
                                                                 entity as EntityObject);
            }

            return(obj);
        }