Azure TableServiceContext 文件中包含多个表还是一张表?

发布于 2024-10-15 00:19:08 字数 1436 浏览 6 评论 0原文

我正在创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2024-10-22 00:19:08

对我来说,这只是代码的可维护性。如果您喜欢多个类,以便一个类的规模不会变得太大,那么将它们分成单独的类可能是一种可行的方法。

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.

忆伤 2024-10-22 00:19:08

表通常没有太多实现,所以我认为每个表和部分类都有一个文件有点混乱。您可能希望对它们进行逻辑分组,因此我建议为每个上下文创建一个文件及其关联的表。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文