2011-01-31 39 views
0

我正在創建一個Azure應用程序,它將使用大約十個存儲表。我想採用最佳做法,但我不確定是否應該只有一個包含dataservicecontext.cs文件中的所有表的單個文件,或者每個表應該有不同的文件。在我看來,兩種方式都能達到同樣的效果。任何人都會對最佳做法有什麼看法?Azure TableServiceContext文件中的許多表或一個表?

public class ContactDataServiceContext 
    : TableServiceContext 
{ 
    public ContactDataServiceContext(string baseAddress, 
     StorageCredentials credentials) 
     : base(baseAddress, credentials) 
    { 
    } 

    public const string ContactTableName = "ContactTable"; 

    public IQueryable<ContactDataModel> ContactTable 
    { 
     get 
     { 
      return this.CreateQuery<ContactDataModel>(ContactTableName); 
     } 
    } 

} 


namespace NerdDinner.Models 
{ 
    public class NerdDinnerDataContext : TableStorageDataServiceContext 
    { 
     /// <summary> 
     /// Define an entry-point into our table. Dinners represents an "EntitySet". 
     /// </summary> 
     public DataServiceQuery<Dinner> Dinners 
     { 
      get 
      { 
       //Create the root of a LINQ query of type Dinner against the table Dinners 
       return this.CreateQuery<Dinner>("Dinners"); 
      } 
     } 

     public DataServiceQuery<RSVP> RSVPs 
     { 
      get 
      { 
       //Create the root of a LINQ query of type RSVP against the table RSVPs 
       return this.CreateQuery<RSVP>("RSVPs"); 
      } 
     } 

    } 
} 
+0

對不起,上面的代碼的格式。我似乎無法讓它顯示正確。我的意思是顯示兩個文件的功能差不多。我知道後者使用了一個過時的庫,但它仍然顯示在該文件中組合了多個表。 – Gordon 2011-01-31 12:58:59

回答

0

對我來說,這只是代碼的可維護性。如果你喜歡很多班級,以便一個班級規模不會變得太大,那麼將這些班級分成不同的班級可能是一條可行的路。

0

對於一個表通常沒有太多實現,所以我認爲每個表和部分類都有一個文件有點麻煩。你可能希望將它們按邏輯分組,所以我建議使用它的關聯表爲每個上下文創建一個文件。