Azure TableServiceContext 文件中包含多个表还是一张表?
我正在创建一个 Azure 应用程序,它将使用大约十个存储表。我想采用最佳实践,但我不确定是否应该只有一个文件包含 dataservicecontext.cs 文件中的所有表,或者是否应该为每个表使用不同的文件。在我看来,这两种方法都达到了同样的目的。其他人对最佳实践有何看法?
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");
}
}
}
}
I'm working on creating an Azure application which would use around ten ttorage tables. I would like to adopt best practices but I am not sure if I should have just one single file with all the tables in the dataservicecontext.cs file or if I should have a different file for each table. Looks to me like both ways achieve the same thing. Anyone else have an opinion on what would be the best practice?
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");
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说,这只是代码的可维护性。如果您喜欢多个类,以便一个类的规模不会变得太大,那么将它们分成单独的类可能是一种可行的方法。
To me this just comes down to code maintainability. If you favor many classes so that one class size does not grow too big, then splitting these out into separate classes might be the way to go.
表通常没有太多实现,所以我认为每个表和部分类都有一个文件有点混乱。您可能希望对它们进行逻辑分组,因此我建议为每个上下文创建一个文件及其关联的表。
There typically isn't much implementation to a table, so I think it's a bit messy to have a file per table and partial classes. You would want to group them logically so I'd recommend creating a file per Context with it's associated tables.