摘要
我的实体数据模型
public class MyEventEntity : TableEntity
{
public Owner Owner { get; set; }
public List<Guest> Guests { get; set; }
public MyEventEntity(string partitionKey, string rowKey)
{
this.PartitionKey = partitionKey;
this.RowKey = rowKey;
this.Guests = new List<Guest>();
}
}//End of class.
public class Guest
{
public string ID { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public Guest()
{
}
}//End of class.
public class Owner
{
public string ID { get; private set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public Owner()
{
}
}//End of class.
问题
更新
我同时感谢任何评论,要么指出语法是否存在问题,要么提出潜在的性能改进建议等。
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var tableClient = storageAccount.CreateCloudTableClient();
//var table = tableClient.GetTableReference(tableName);
//table.CreateIfNotExists();
var tableServiceContext = tableClient.GetDataServiceContext();
IEnumerable<MyEventEntity> query = from entity in
tableServiceContext.CreateQuery<MyEventEntity>("myevententities")
where entity.PartitionKey.Equals("SomeValue")
|| entity.Owner.ID.Equals("SomeValue")
|| entity.Guests.Where(ID => ID == "SomeValue")
select entity;
//////////////////////////////////////////////////////////////////
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var tableClient = storageAccount.CreateCloudTableClient();
//var table = tableClient.GetTableReference(tableName);
//table.CreateIfNotExists();
var tableServiceContext = tableClient.GetDataServiceContext();
var query = (from entity in tableServiceContext.CreateQuery<MyEventEntity>("myevententities")
where entity.PartitionKey.Equals("SomeValue")
|| entity.Owner.ID.Equals("SomeValue")
|| entity.Guests.Where(ID => ID == "SomeValue")
select new MyEventEntity()).AsTableServiceQuery();
return query.ToList<MyEventEntity>();
//////////////////////////////////////////////////////////////////
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var tableClient = storageAccount.CreateCloudTableClient();
//var table = tableClient.GetTableReference(tableName);
//table.CreateIfNotExists();
var tableServiceContext = tableClient.GetDataServiceContext();
IEnumerable<MyEventEntity> query =
tableServiceContext.Where(pk => pk.PartitionKey.Equals("SomeValue")
|| oID => oID.Owner.ID.Equals("SomeValue")
|| gID => gID.Guests.Where(ID => ID.Equals("SomeValue")).ToList();
更新2