New Posts New Posts RSS Feed: Finding an Entity by Primary Key in a Binding Source returns -1
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Finding an Entity by Primary Key in a Binding Source returns -1

 Post Reply Post Reply
Author
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Topic: Finding an Entity by Primary Key in a Binding Source returns -1
    Posted: 12-Jul-2007 at 10:39am

At some point in my application I need to find the employee using the value of his primary key ( I have that value of primary key ).

I tried something like:

 

bindingSource1.Position=bindingSource1.Find(“IdEmployee”, valueOfPrimaryKeyIKnowIt);

 

but bindingSource1.Find(“IdEmployee”, valueOfPrimaryKeyIKnowIt) returns -1.

 

I know how to get the independent Employee using:

 

PrimaryKey pk = new PrimaryKey(typeof(Employee), valueOfPrimaryKeyIKnowIt);

Employee anEmployee = MainPm.Manager.GetEntity<Employee>(pk, QueryStrategy.Normal);

 

But I don’t need an independent object; I need to keep in bindingSource1 all Employees  but to be able to set current position to an Employee by his primary key.

 

Can you help me ?

 

Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 12-Jul-2007 at 10:43am
We found that in fact the BindingSource Find method will return a correct result if the data type of the second parameter exactly matches the data type of the property whose name is given in the first parameter.  In my testing, for example, I did a Find call on a BindingSource instance that was populated with OrderSummary entities from our IdeaBladeTutorial sample database.  I specified "Id" as the column name to search on and a particular value of Id to find.  I saw the same symptoms you did, namely that the call returned -1.  When I encapsulated my Id value to find in a Convert.ToInt64() call, remembering that the "Id" column is of type Int64, the find call returned the correct result.
 
Please try using the Find command, making sure that the data types of the column you are searching on and the value you are searching for match exactly. 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down