Linq 分区关键问题

Linq 分区关键问题,linq,azure,azure-table-storage,Linq,Azure,Azure Table Storage,让我这样定义我的实体: public class User : TableServiceEntity { /// <summary>Unique Id (Row Key)</summary> public string Id { get { return RowKey; } set { RowKey = value; } } /// <summary>Gets or sets the u

让我这样定义我的实体:

public class User : TableServiceEntity
{
    /// <summary>Unique Id (Row Key)</summary>
    public string Id
    {
        get { return RowKey; }
        set { RowKey = value; }
    }

    /// <summary>Gets or sets the username (Partition Key)</summary>
    public string Username
    {
        get { return PartitionKey; }
        set { PartitionKey = value; }
    } 
}
公共类用户:表服务实体
{
///唯一Id(行键)
公共字符串Id
{
获取{return RowKey;}
设置{RowKey=value;}
}
///获取或设置用户名(分区键)
公共字符串用户名
{
获取{return PartitionKey;}
设置{PartitionKey=value;}
} 
}
下面的Linq查询是否使用分区键

var ctx = ServiceLocator.Get<UserDataServiceContext>();
return ctx.Users.Where(x => x.Username == Username).FirstOrDefault();
var ctx=ServiceLocator.Get();
返回ctx.Users.Where(x=>x.Username==Username.FirstOrDefault();

很肯定不会。不过,您可以用Fiddler验证这一点。如果您在连线上没有看到带有PartitionKey和RowKey的$filter,那么您不是在按它们进行查询(这可能是不好的)。我相信您将拥有一个具有4个属性(PK、RK、Id和用户名)的实体,并且您将查询的属性将不会被索引。

对基类属性的属性访问存在于呈现给驱动程序的Linq表达式树中。所以这完全取决于司机的聪明程度。但我同意这种可能性很小:)