<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:55 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-466] Unsupported where clause</title>
                <link>https://jira.mongodb.org/browse/CSHARP-466</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Tried to use expressions to build where clause dynamically, but couldn&apos;t use even simple expression - throws error &quot;Unsupported where clause: &amp;lt;InvocationExpression&amp;gt;&quot;&lt;/p&gt;


&lt;p&gt;Here is code snippet.&lt;/p&gt;

&lt;p&gt; var entry = Expression.Parameter(typeof(BasePriceEntry), &quot;c&quot;);   &lt;br/&gt;
 var x = Expression.Lambda&amp;lt;Func&amp;lt;BasePriceEntry, bool&amp;gt;&amp;gt;(Expression.Equal(entry.Property(&quot;CatId&quot;), Expression.Constant(cat)), entry).Compile();&lt;br/&gt;
 var db = Server.GetDatabase(DB);&lt;/p&gt;

&lt;p&gt;            using (Server.RequestStart(db))&lt;/p&gt;
            {
                var collection = db.GetCollection&amp;lt;BasePriceEntry&amp;gt;(COLLECTION_CONST);
                var items = from c in collection.AsQueryable&amp;lt;BaseEntry&amp;gt;() where x(c) &amp;amp;&amp;amp; c.LowerText.Contains(filterText.ToLower()) select c;
                return items.ToArray();
            }

&lt;p&gt;Here is stack trace.&lt;/p&gt;

&lt;p&gt;   &#1074; MongoDB.Driver.Linq.SelectQuery.BuildQuery(Expression expression) &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 784&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.SelectQuery.BuildAndAlsoQuery(BinaryExpression binaryExpression) &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 269&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.SelectQuery.BuildQuery(Expression expression) &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 751&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.SelectQuery.BuildQuery() &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 113&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.SelectQuery.Execute() &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 122&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 147&lt;br/&gt;
   &#1074; MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator() &#1074; C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryable.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 81&lt;br/&gt;
   &#1074; System.Linq.Buffer`1..ctor(IEnumerable`1 source)&lt;br/&gt;
   &#1074; System.Linq.Enumerable.ToArray&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source)&lt;br/&gt;
   &#1074; dblib.DataBaseLayer.FindEntries(String filterText, Int32 cat, Int32 pr1, Int32 pr2) &#1074; F:\Projects\my\site\dblib\DataBaseLayer.cs:&#1089;&#1090;&#1088;&#1086;&#1082;&#1072; 147&lt;/p&gt;</description>
                <environment>Tested on win 7, .net 4.0</environment>
        <key id="37967">CSHARP-466</key>
            <summary>Unsupported where clause</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="ydanila">Yakov D</reporter>
                        <labels>
                            <label>Expression</label>
                            <label>question</label>
                    </labels>
                <created>Mon, 7 May 2012 17:11:13 +0000</created>
                <updated>Fri, 5 Apr 2019 13:58:56 +0000</updated>
                            <resolved>Mon, 7 May 2012 18:03:47 +0000</resolved>
                                    <version>1.4.2</version>
                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="116858" author="ydanila" created="Mon, 7 May 2012 18:01:12 +0000"  >&lt;p&gt;I made several tests using different expressions and extension methods - works without any error.  Thank you very much for help.&lt;/p&gt;</comment>
                            <comment id="116848" author="craiggwilson" created="Mon, 7 May 2012 17:45:48 +0000"  >&lt;p&gt;If you are going to be dynamically building expression like this, I&apos;d highly suggest you not using the linq syntax and using the extension method syntax.  The below code should work properly although I tested with a slight variant as I don&apos;t have any idea what your entities look like.  Note that the dynamic expression is NOT compiled because we need to look at the expression tree, not the il code in order to pass the query to the server.&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var entry = Expression.Parameter(typeof(BasePriceEntry), &quot;c&quot;);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var x = Expression.Lambda&amp;lt;Func&amp;lt;BasePriceEntry, bool&amp;gt;&amp;gt;(Expression.Equal(Expression.Property(entry, &quot;CatId&quot;), Expression.Constant(cat)), entry); //note, don&apos;t compile this&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var items = db.GetCollection&amp;lt;BasePriceEntry&amp;gt;(COLLECTION_CONST).AsQueryable&amp;lt;BaseEntry&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;items = items.Where(c =&amp;gt; c.LowerText.Contains(filterText.ToLower());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;items = items.Where(x); //just pass it in&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;return items.ToArray()&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Let me know if you need further help.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh7kn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14026</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>