I'm attempting to try this as well. I'm hot on the trail but not having success. Here are several methods that I've tried, in addition to the <asp:EntityDataSource>
I cannot get any of the four methods I've listed to work. On the first try where I assign the currently logged in UserID to strGuidNum, I get an error "Object reference not set to an instance of an object". What would be the object that I need to instantiate.
The other three methods have some sort of error in the syntax.
Do you have any suggestions on resolving this?
To be conscious that you are ignorant is a great step to knowledge.
- Benjamin Disraeli (1804 - 1881), Sybil, 1845
This seems to work - I have it on the 'Selecting' event of the EntityDataSource, but I'm sure can be used elsewhere, replacing e.DataSource with the name of your EntityDataSource.
werkflo
0 Points
4 Posts
EntityDataSource - passing a guid to a where/whereparameters
Jan 29, 2012 10:45 PM|LINK
How do you pass a guid to a entitydatasource where, or whereparameter?
I can't get around: "The argument types 'Edm.Guid' and 'Edm.String' are incompatible for this operation."
I've tried:
Where="it.[ApplicationId] = '801dee7f-0f5b-4572-a261-fd55b9e4f0ad'
Where="it.[ApplicationId] = 801dee7f-0f5b-4572-a261-fd55b9e4f0ad
AspNetUsersEntityDataSource.WhereParameters.Add("ApplicationId", TypeCode.Object, "801dee7f-0f5b-4572-a261-fd55b9e4f0ad");
entitydatasource
Icemania
Member
100 Points
148 Posts
Re: EntityDataSource - passing a guid to a where/whereparameters
Jan 30, 2012 02:09 PM|LINK
You need to convert your guid string into a true guid. Something like:
Where="it.[ApplicationId]='+new Guid("801dee7f-0f5b-4572-a261-fd55b9e4f0ad")
untested but i know you'll have to convert the string to a guid before hand
entitydatasource
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: EntityDataSource - passing a guid to a where/whereparameters
Jan 31, 2012 12:21 AM|LINK
Hello werkflo:)
Another way is that you can use code-behind:
EntityDataSource1.WhereParameters["GuidNum"].Value = new Guid("……");
In EntityDataSource's aspx codes' defination——
Where="it.[ApplicationId] = @GuidNum"
entitydatasource
beef410dc
Member
5 Points
15 Posts
Re: EntityDataSource - passing a guid to a where/whereparameters
Jun 16, 2012 02:45 AM|LINK
Decker,
I'm attempting to try this as well. I'm hot on the trail but not having success. Here are several methods that I've tried, in addition to the <asp:EntityDataSource>
//CODE BEHIND string strGuidNum = Membership.GetUser().ProviderUserKey.ToString(); CleaningGridViewEDS.WhereParameters["GuidNum"].DefaultValue = strGuidNum; CleaningGridViewEDS.WhereParameters["GuidNum"].DefaultValue = (Guid)Membership.GetUser().ProviderUserKey; CleaningGridViewEDS.WhereParameters["GuidNum"].DefaultValue = new Guid((Guid)Membership.GetUser().ProviderUserKey); CleaningGridViewEDS.WhereParameters["GuidNum"].DefaultValue = new Guid(Membership.GetUser().ProviderUserKey); //ASPX <asp:EntityDataSource ID="CleaningGridViewEDS" runat="server" ConnectionString="name=HmsEntitiesConnectionString" DefaultContainerName="HmsEntitiesConnectionString" EnableFlattening="False" EntitySetName="CleaningDatas" EnableDelete="True" EnableInsert="True" EnableUpdate="True" OrderBy="it.[DueDate]" Where="it.[AssignedTo] == @AssignedTo AND it.[IsCompletedFlag] == 'n' AND it.[SubmittedByUserID] == @GuidNum "> <WhereParameters> <asp:ControlParameter Name="AssignedTo" ControlID="ddlFilterByPerson" Type="String" DefaultValue="null" /> </WhereParameters> </asp:EntityDataSource>I cannot get any of the four methods I've listed to work. On the first try where I assign the currently logged in UserID to strGuidNum, I get an error "Object reference not set to an instance of an object". What would be the object that I need to instantiate.
The other three methods have some sort of error in the syntax.
Do you have any suggestions on resolving this?
- Benjamin Disraeli (1804 - 1881), Sybil, 1845
drgregory
Member
2 Points
1 Post
Re: EntityDataSource - passing a guid to a where/whereparameters
Jan 02, 2013 01:40 PM|LINK
This seems to work - I have it on the 'Selecting' event of the EntityDataSource, but I'm sure can be used elsewhere, replacing e.DataSource with the name of your EntityDataSource.
Parameter clientParameter = new Parameter("ClientID",DbType.Guid, SelectedClientID.ToString());
e.DataSource.WhereParameters.Add(clientParameter);
e.DataSource.Where += "it.[ClientID] == @ClientID";
Ian