private void AddSort(LambdaExpression lambda, bool isStarting, bool ascending)
        {
            var body = lambda.Body as MemberExpression;

            if (body == null)
            {
                throw new NotSupportedException($"The expression {lambda} cannot be used in an Order clause");
            }

            if (isStarting)
            {
                if (_optionalSortOrderHandle == null)
                {
                    _optionalSortOrderHandle = _realm.MakeSortOrderForTable(_retType);
                }
                else
                {
                    var badCall = ascending ? "By" : "ByDescending";
                    throw new NotSupportedException($"You can only use one OrderBy or OrderByDescending clause, subsequent sort conditions should be Then{badCall}");
                }
            }

            var sortColName = body.Member.Name;

            NativeSortOrder.add_sort_clause(_optionalSortOrderHandle, sortColName, (IntPtr)sortColName.Length, ascending ? (IntPtr)1 : IntPtr.Zero);
        }
Exemple #2
0
        internal static SortOrderHandle CreateSortOrderHandle(IntPtr sortOrderPtr)
        {
            var sortOrderHandle = new SortOrderHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* Retain handle in a constrained execution region */ }
            finally
            {
                sortOrderHandle.SetHandle(sortOrderPtr);
            }
            return(sortOrderHandle);
        }
Exemple #3
0
 internal static extern void add_sort_clause(SortOrderHandle sortOrderHandle,
                                             [MarshalAs(UnmanagedType.LPWStr)] String columnName, IntPtr columnNameLen, IntPtr ascending);
Exemple #4
0
 internal static extern IntPtr create_for_query_sorted(SharedRealmHandle sharedRealm, QueryHandle queryPtr, IntPtr objectSchema, SortOrderHandle sortOrderHandle);
Exemple #5
0
 internal static extern IntPtr create_for_table_sorted(SharedRealmHandle sharedRealm, TableHandle handle, IntPtr objectSchema, SortOrderHandle sortOrderHandle);
Exemple #6
0
        internal ResultsHandle MakeResultsForQuery(Type tableType, QueryHandle builtQuery, SortOrderHandle optionalSortOrder)
        {
            var    objSchema  = Realm.ObjectSchemaCache[tableType];
            IntPtr resultsPtr = IntPtr.Zero;

            if (optionalSortOrder == null)
            {
                resultsPtr = NativeResults.create_for_query(SharedRealmHandle, builtQuery, objSchema);
            }
            else
            {
                resultsPtr = NativeResults.create_for_query_sorted(SharedRealmHandle, builtQuery, objSchema, optionalSortOrder);
            }
            return(CreateResultsHandle(resultsPtr));
        }