2011-07-18 13 views
0

我有下面的類:我如何可以設置RowKey到一個新值序列

public class Note : TableServiceEntity 
{ 
    public Note() 
    { 
    } 

    public Note(string pK) 
    { 
     PartitionKey = pK, 
     RowKey = Seq.GetSequence().ToString(); 
    } 
    public string Description { get; set; } 
} 

我需要的是設置RowKey由序列生成的值。任何人都可以解釋如何用構造函數做到這一點?我得到的是一個語法錯誤:Virtual member call in constructor

回答

0
public static class Seq 
{ 
    static int index; 
    public static int GetSequence() 
    { 
     return index++; 
    } 
} 

public class Note : TableServiceEntity 
{ 
    public Note(string partitionKey, string rowKey) 
     : base(partitionKey, Seq.GetSequence().ToString()) { } 
} 
+0

我想你需要從Note()構造函數中刪除第二個參數,因爲這不需要。而且它仍然需要空構造函數,因爲這是從表存儲器反序列化時使用的。 – knightpfhor

+0

是的,代碼可以重新考慮,但答案仍然有效,因爲它回答了她的問題。這只是一些僞代碼模型。不過謝謝。 – 2011-07-19 09:26:50

相關問題