开发者

TableServiceContext and strongly typed table name

开发者 https://www.devze.com 2023-03-11 03:38 出处:网络
I have a DocumentDataServiceContext derived from TableServiceContext. Inside that class I have the following method:

I have a DocumentDataServiceContext derived from TableServiceContext. Inside that class I have the following method:

public DataServiceQuery<Doc开发者_StackOverflowument> Documents
{
    get
    {
        return this.CreateQuery<Document>("Documents");
    }
}

Is there a way to get rid of the string constant passed to CreateQuery and instead obtain the table name used by CloudTableClient.CreateTablesFromModel(typeof(DocumentDataServiceContext))?


No. At the end of the day, the CreateQuery() must have the table name to query against. You can of course use convention or reflection to derive what that table name will be in another method, but at some point a string must be passed to CreateQuery.

public DataServiceQuery<T> CreateQueryByConvention<T>()
{
     return this.CreateQuery<T>(typeof(T).ToString());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消