LLBLGenProDataSource, Gridview, Querystring, Guid

Posts   
 
    
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 13-Jul-2006 14:01:37   

Hello, Searched the forums and couldn't find anyything that fit my situation. I have a gridview on a page bound to a LLBLGenProDatasource. The datasource will receive its selectparameter from the querystring called CompanyGuid which is obviously in a guid format. The issue I'm having is that the llbgenprodatasource does not want to filter using this value. I'm unsure as to what the cause is but I'm guessing it may have something to do with the guid in the querystring being presented to the llblgenprodatasource control as a string. Thoughts on how I can get this to work? Below is my code, Thanks in advance:


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="UserInfoGuid"
        DataSourceID="LLBLGenProDataSource1" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" 
        GridLines="None">
        <Columns>
            <asp:BoundField DataField="CompanyGuid" HeaderText="CompanyGuid" SortExpression="CompanyGuid" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
            <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
            <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" SortExpression="CreateDate" />
            <asp:BoundField DataField="ModDate" HeaderText="ModDate" SortExpression="ModDate" />
            <asp:CheckBoxField DataField="Active" HeaderText="Active" SortExpression="Active" />
            <asp:CommandField ShowSelectButton="True" />
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <cc1:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" DataContainerType="EntityCollection"
        EntityCollectionTypeName="DiamondMSI.CollectionClasses.UserInfoCollection, DiamondMSI">
        <SelectParameters>
            <asp:QueryStringParameter Name="CompanyGuid" QueryStringField="CompanyGuid" />
        </SelectParameters>
    </cc1:LLBLGenProDataSource>
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jul-2006 16:16:19   

I don't know the solution, but I came across this link: http://funkenbusch.com/archive/2006/06/10/5.aspx

Tell me if it helps you out.

bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 13-Jul-2006 17:04:42   

Thanks for the tip, I will try the suggestion out later tonight and let you know how it goes.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 13-Jul-2006 17:06:30   

I see it's also a problem with MS' original controls. For what's worth: I can eventually add code which overcomes this, I'm not sure if it will work, but if this suggestion fails, let me know and I'll see what I can do.

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 14-Jul-2006 17:52:46   

Hi, Just wanted to give you a heads up that the solution that I was pointed to by Walaa did indeed do the trick to a certin extent. I create a class in my App_code folder called GuidParameter.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for GuidParameter
/// </summary>
/// 

namespace GridViewHelper
{
    public class GuidParameter : QueryStringParameter
    {
        public GuidParameter()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        protected override object Evaluate(HttpContext context, Control control)
        {
            //return new Guid(context.Request.QueryString[base.QueryStringField]);
            return new Guid("0a586075-b930-4878-82aa-76908aa32c6d");
        }
    }
}


I then added the following into my web.config:


<pages>
     <controls>
       <add tagPrefix="nsGVH" namespace="GridViewHelper"/>
    </controls>
</pages>

I then used the following for my LLBLGenProDatasource:


<cc1:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="DiamondMSI.CollectionClasses.UserInfoCollection, DiamondMSI">
        <SelectParameters>
            <nsGVH:GuidParameter Name="CompanyGuid" QueryStringField="CompanyGuid" />
        </SelectParameters>
</cc1:LLBLGenProDataSource>

However, I am having a problem in the GuidParameter.cs file with this line which is currently commented out:


return new Guid(context.Request.QueryString[base.QueryStringField]);

Evaluation of 'context.Request.QueryString[base.QueryStringField]' returns a null. This is a headscratcher because 'base.QueryStringField' returns the string 'CompanyGuid' and poking through the 'context.Request.QueryString' shows there is a key in there called 'CompanyGuid', but putting all together context.Request.QueryString[base.QueryStringField]) gives me null. Most bizarre, though I'm thining I'm just missing something really basic. I have verified that if I plug a hardcoded guid string into the return new Guid code that the llblgenprodatasource does indeed get me the results I'm looking for. Thoughts? Thanks. Brett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 15-Jul-2006 20:55:41   

I use internally Convert.ChangeType() to convert the string to a type. It turns out that ChangeType doesn't support a guid.

I think it would be best if I add some code which converts the string to a guid, if the field's type is Guid. It saves you a lot of problems I think simple_smile

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 16-Jul-2006 19:27:35   

So the change you are proposing would take care of my issue and I wouldn't have to use some custom GuidParameter thing. When do you think this would be implemented? Thanks. Brett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 16-Jul-2006 20:43:13   

Correct. Coming week (monday/thuesday)

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 25-Jul-2006 20:29:01   

Frans, Was wondering what the status of this update is? Thanks. B

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 25-Jul-2006 21:39:42   

This is available simple_smile See changelog viewer in the customer area simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Rogken
User
Posts: 6
Joined: 27-Jan-2006
# Posted on: 26-Jul-2006 03:03:40   

Thanks Frans. I will check it out. B

bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 27-Jul-2006 04:34:19   

Hi, Back again. I retrieved the newest runtime classes for LLBLGEN 2.0 and added them to my project. Going back to my initial code example, whereas when i first was running the page I was not getting any results now I'm getting an error. So maybe we are making progress here. Here is the error info:

An exception was caught during the execution of a retrieval query: Failed to convert parameter value from a String to a Guid.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. 

the stack trace is:

[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Failed to convert parameter value from a String to a Guid.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +215
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityCollection collectionToFill, Boolean allowDuplicates, IEntityFields fieldsUsedForQuery) +422
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Int32 pageNumber, Int32 pageSize) +271
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse) +97
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetMulti(ITransaction containingTransaction, IEntityCollection collectionToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IEntityFactory entityFactoryToUse, IPredicate selectFilter, IRelationCollection relations, IPrefetchPath prefetchPathToUse, Int32 pageNumber, Int32 pageSize) +66
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, Int32 pageNumber, Int32 pageSize) +110
   SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, Int32 pageNumber, Int32 pageSize) +29
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelectEntityCollection(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) +342
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +104
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +13
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +140
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68
   System.Web.UI.WebControls.GridView.DataBind() +5
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +61
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +67
   System.Web.UI.Control.EnsureChildControls() +97
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5729

Am I missing something ridiculously easy? Thanks. B

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 27-Jul-2006 10:37:57   

Hmm, that would suggest the value is stored as string... I'll check it out.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 28-Jul-2006 13:34:13   

The error is in some other part: the filter creation. the code I added was for inserting/updating an entity with a GUID value. Also required, but not what you're looking for.

(edit). Ok I've fixed it. If you want, I could send you a build of the runtime now, so you can start right away, or you've to wait till the next build.

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 28-Jul-2006 19:37:23   

Frans, Yeah, if it's not too much trouble can you go ahead and send it to bdeline AT hotmail.com. Thanks for the quick response. B

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 28-Jul-2006 20:15:15   

Sent! simple_smile

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 29-Jul-2006 18:31:36   

Frans, Sorry I didn't get at that account, hotmail probably blocked it. If you think the new build will be up early this week then I can wait till then. If you think it might take a bit longer than that can you send the runtimes to brett AT gen4systems.com? Thanks. Brett

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Jul-2006 10:44:41   

bdeline wrote:

Frans, Sorry I didn't get at that account, hotmail probably blocked it. If you think the new build will be up early this week then I can wait till then. If you think it might take a bit longer than that can you send the runtimes to brett AT gen4systems.com? Thanks. Brett

It will be up early this week (monday/thuesday simple_smile )

Frans Bouma | Lead developer LLBLGen Pro
bdeline
User
Posts: 13
Joined: 13-Jul-2006
# Posted on: 02-Aug-2006 01:22:18   

Frans, Just downloaded the newest runtimes. Your fix did the trick and I'm able to use guids in the querystring as a select parameter for a gridview. Thanks for all the help. Brett