Domanda

Sto cercando di filtrare i dati dal EntityReference senza fortuna. Senza la clausola dove funziona bene con la clausola WHERE ottengo il seguente errore:

Il server non ha fornito una risposta significativa; questo potrebbe essere causato da una mancata corrispondenza contratto, un arresto prematuro della sessione o un interno Errore del server.

Ecco il mio metodo che chiama il CrmService:

/// <summary>
        /// Gets the categories.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<category> GetCategoriesExcludingSomething()
        {
            IEnumerable<category> data = CrmClient.categorySet.OrderBy(x => x.SubCategory).ThenBy(x => x.itf_name);

            return data.Where(x => x.SubCategory.ToString() == "SomethingToExclude");
        }

Ho provato con SubCategory.Name anche ma dà lo stesso errore. Penso che sia legato al fatto che utilizza l'associazione anticipata o qualcosa del genere, ma non ho potuto ottenere qualsiasi informazione utile durante il debug.

Qualche consiglio o aiuto sarebbe grande, questo dovrebbe essere facile: /

È stato utile?

Soluzione

According to this documentation: http://technet.microsoft.com/en-us/library/gg328328.aspx

The LINQ query provider supports a subset of the LINQ operators. Not all conditions that can be expressed in LINQ are supported.

orderBy supports ordering by entity attributes, such as Contact.FullName.

What you could do is to use the where clause first, and then use the ToList() method. After this, you'll have a collection of data on which you can use all the common Linq queries.

Also, trying to OrderBy an EntityReference is not the good way to do it. You should try ordering like this:

OrderBy(x => x.SubCategory.Id)

where: The left side of the clause must be an attribute name and the right side of the clause must be a value. You cannot set the left side to a constant. Both the sides of the clause cannot be constants. Supports the String functions Contains, StartsWith, EndsWith, and Equals

What you could do here is either filtering values by the Id or by the Name (that's the only relevant informations you'll have from the EntityReference in this case).

Where(x => x.SubCategory.Name == "CategoryNameToExclude");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top