﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mark van Aalst &#187; linq</title>
	<atom:link href="http://www.markvanaalst.net/category/linq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markvanaalst.net</link>
	<description>blogging about ASP.Net and web development related techniques</description>
	<lastBuildDate>Thu, 18 Feb 2010 18:12:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dynamic load where parameters for linqDatasource</title>
		<link>http://www.markvanaalst.net/2008/04/21/dynamic-load-where-parameters-for-linqdatasource/</link>
		<comments>http://www.markvanaalst.net/2008/04/21/dynamic-load-where-parameters-for-linqdatasource/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 11:39:27 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[linq]]></category>

		<guid isPermaLink="false">http://www.markvanaalst.com/?p=3</guid>
		<description><![CDATA[When using an Linq Datasource (linq to sql) for a datagrid (Gridview, ListView, etc) you don&#8217;t always want all rows from a table. To exclute data you can use the WhereParameters to add an where statement to your DataSource. You can do limited where statements with the Visual Studio Wizards. When you need more than a [...]]]></description>
			<content:encoded><![CDATA[<p>When using an Linq Datasource (linq to sql) for a datagrid (Gridview, ListView, etc) you don&#8217;t always want all rows from a table. To exclute data you can use the WhereParameters to add an where statement to your DataSource.</p>
<p>You can do limited where statements with the Visual Studio Wizards. When you need more than a limited statement you can dynamicly create an Parameter to add to your Linq DataSource.</p>
<p>The following examples shows how to filter the Linq Datasource that recovers all rows from the <em>Post </em>table and filters them on the BlogId. The <em>BlogManager.CurrentBlogId</em> gets the blog GUID from the Session.</p>
<p>[code:c#]<br />
   Parameter whereparam = new Parameter();<br />
   whereparam.Name = "BlogId";<br />
   whereparam.DefaultValue = BlogManager.CurrentBlogId.ToString();<br />
   whereparam.Type = TypeCode.Object;<br />
   linqDataSource.WhereParameters.Add(whereparam);<br />
   linqDataSource.Where = "BlogId == <strong>Guid(@BlogId)</strong>";<br />
[/code]</p>
<p>You convert the <em>@BlogId </em>(string) to a Guid In the<em> linqDataSource.Where </em>property otherwise you get the following error<em>:<br />
</em></p>
<h2><em>Operator &#8216;==&#8217; incompatible with operand types &#8216;Guid&#8217; and &#8216;String&#8217; </em></h2>
<p><span style="font-family: Arial, Helvetica, Geneva, SunSans-Regular, sans-serif;"><em><strong><span style="font-family: Verdana;">Description: </span></strong>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>
<p><strong><span style="font-family: Verdana;">Exception Details: </span></strong>System.Web.Query.Dynamic.ParseException: Operator &#8216;==&#8217; incompatible with operand types &#8216;Guid&#8217; and &#8216;String&#8217; </em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.markvanaalst.net/2008/04/21/dynamic-load-where-parameters-for-linqdatasource/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
