所以问题是: 我有一个类似40个属性的实体(所有在代码中都正确定义为“public String PropertyName {get; set;}”。 当我插入新实体时,大多数属性都被存储,但其中一些不是。
代码如下:
public class PostTableEntity : TableEntity
{
#region Fields
#endregion
#region Properties
public Guid CreatorId { get; set; }
public String HtmlText { get; set; }
public String SubjectIds { get; set; }
public String QuoteString { get; set; }
public double GeoLat { get; set; }
public double GeoLong { get; set; }
public String GeoPlace { get; set; }
public Int32 TotalSmiles { get; set; }
public DateTime DateUTC { get; set; }
public Guid? EventId { get; set; }
public string EventName { get; set; }
public String ExcludedUsers { get; set; }
public String Comment00_Text { get; set; }
public Guid Comment00_UserId { get; set; }
public Guid Comment00_CommentId { get; set; }
{...} //Some more props - no more than 30 in total
public String VeryImportantData { get; set; }
#endregion
#region Constructors
public PostTableEntity()
{
}
public PostTableEntity(String partitionKey, String rowKey, Guid creatorId, DateTime dateUTC, String htmlText)
: base(partitionKey, rowKey)
{
this.CreatorId = creatorId;
this.HtmlText = htmlText;
this.DateUTC = dateUTC;
}
#endregion
#region Methods
public void SetSubjectIdsList(List<Guid> subjectIds)
{
if (subjectIds != null)
{
this.SubjectIds = String.Join(";", subjectIds);
}
else
{
this.SubjectIds = "";
}
}
#endregion
}
...然后有一个派生类:
public class ImagePostTableEntity : PostTableEntity
{
#region Fields
#endregion
#region Properties
public String StorageAccountName { get; set; }
public String StorageContainerName { get; set; }
public String BlobName_Original { get; set; }
public String BlobName_Large { get; set; }
public String BlobName_Medium { get; set; }
public String BlobName_Small { get; set; }
#endregion
#region Constructors
public ImagePostTableEntity()
{
}
public ImagePostTableEntity(String partitionKey, String rowKey, Guid creatorId, DateTime date, String htmlText, List<Guid> subjectIds, String storageAccountName, String storageContainerName, String blobName_Original, String blobName_Large, String blobName_Medium, String blobName_Small)
: base(partitionKey, rowKey, creatorId, date, htmlText)
{
this.StorageAccountName = storageAccountName;
this.StorageContainerName = storageContainerName;
this.BlobName_Original = blobName_Original;
this.BlobName_Large = blobName_Large;
this.BlobName_Medium = blobName_Medium;
this.BlobName_Small = blobName_Small;
this.SetSubjectIdsList(subjectIds);
}
}
所以我这样称之为InsertOperation(我认为没什么特别的):
ImagePostTableEntity newPost = new ImagePostTableEntity(streamId.ToString(), newPostId.ToString(), creatorId, date, htmlText, subjectIds, storageAccountName, storageContainerName, blobName_Original, blobName_Large, blobName_Medium, blobName_Small); //This construcotr calls inner method: SetSubjectIdsList(subjectIds);
newPost.TotalComments = 0;
newPost.VeryImportantData = "That very important string";
TableOperation insertOperation = TableOperation.Insert(newPost);
执行此操作后,实体存在于表存储中,但不存储某些属性。具体而言,不存储“SubjectIds”和“VeryImportantData”。它们不为空,它们有一些值(双重检查;))
答案 0 :(得分:0)
除了Emily提到的没有执行方法的内容之外,我还没有看到为subjectIds设置值的代码。艾米丽提出的另一个好处是,你如何验证该实体没有这些属性?
尝试使用fiddler确保确实发送了某些内容。
我很确定您之前已经看过this guidance,但请再次检查以确保您没有遗漏任何内容。
请记住,在执行Insert操作时,如果该表中已存在具有相同PK和RK的实体,则不会插入实体。 InsertOrReplace操作将允许您执行此操作。