Menu

3 primary keys

2006-09-11
2013-04-03
  • Nobody/Anonymous

    Hi,

    I would like to use a key for retrieve Gentle object but my class has 3 primary keys columns...
    And Key object accept only 1 or 2 primary keys object.

    Can you help me please ?

    Thanks

     
    • Scott

      Scott - 2006-09-11

      This could be very easy with Gentle 2.0 (and perhaps Gentle 1.2.9, but I do not use that release).

      Instead of using Keys for your query criteria as you normally would, simply use LogicalExpression.Equals

      For for instance, if you wanted to retrieve and object that has primary key columns Key1, Key2 and Key3, it might look something like the following:

      LogicalExpression exp = LogicalExpression.Equals(new Field("Key1"), new Value(yourKey1Value));
      exp = LogicalExpression.And(exp, LogicalExpression.Equals(new Field("Key2"), new Value(yourKey2Value)));
      exp = LogicalExpression.And(exp, LogicalExpression.Equals(new Field("Key3"), new Value(yourKey3Value)));
      return GentleProvider.Session.RetrieveInstance<YourObjectType>(RequestFlags.None, exp);

      Don't forget that GentleProvider should be replaced with your actual provider instance, whatever it may be. This query will return the row where Key1, Key2, and Key3 match your provided values.

      This is just one way to do it, I'm sure there might be more.

       
    • Christophe

      Christophe - 2006-09-12

      With Gentle 1.2.9, you could perhaps try :

      Key myKey = new Key( typeof(myobjectType), true);
      myKey.Add("myKeyField1", value1);
      myKey.Add("myKeyField2", value2);
      myKey.Add("myKeyField3", value3);
      myObjectType myObject = (myObjectType)Broker.RetrieveInstance( typeof(myObjectType), myKey );

      Hope this will help.

       

Log in to post a comment.