How to CreateTableDefinition with composite key?

Dec 12, 2010 at 6:44 PM

OK I have a ViewModel that represents a underlying table with a composite key. I wanted to know if SterlingDB handles this story and how would I go about using CreateTableDefinition to do it. Thanks

Dec 12, 2010 at 7:32 PM

Use a tuple or a class. For example:

public class MyKey 
    public MyKey(int key1, int key2, int key3, string key4)
         Key1 = key1;
         Key2 = key2;
         Key3 = key3;
         Key4 = key4;
    public int Key1 { get; set; }
    public int Key2 { get; set; }
    public int Key3 { get; set; }
    public string Key4 { get; set; }
    public override bool Equals(object other) 
         var otherkey = other as MyKey;
         if (otherkey == null) return false;
         return otherkey.Key1 == Key1 && 
             otherkey.Key2 == Key2 &&
             otherkey.Key3 == Key3 &&

    public override int GetHashCode()
        return string.Format("{0}{1}{2}{3}",
           Key1, Key2, Key3, Key4).GetHashCode();

// define the key
k => new MyKey(k.Key1, k.Key2, k.Key3, k.Key4)
Dec 13, 2010 at 1:20 PM

I've provided some examples and unit tests in the latest source drop and documented it on the Wiki here: