我正在尝试将用户存储到我的 Azure 表中,但是在尝试创建用户时,我得到“对象未设置为对象的实例”,为什么???
UserEntity entry = new UserEntity();
entry.UserName = pUserName;
entry.MiniatureImageURL = blob.Uri.ToString();
entry.PhotosUrl.Add(blob.Uri.ToString()); //THIS IS A LIST of strings
Connection cn = new Connection();
cn.AddUserEntries(entry);
我的连接类定义如下:
在这里,我尝试将新用户添加到当前上下文,然后尝试将项目保存在存储中:
public void AddUserEntries(UserEntity newItem)
{
try
{
this.context.AddObject("UserEntity", newItem);
this.context.SaveChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
static Connection()
{
try
{
storageAccount = CloudStorageAccount.FromConfigurationSetting("dataconnectionstring");
CloudTableClient.CreateTablesFromModel(
typeof(Connection),
storageAccount.TableEndpoint.AbsoluteUri,
storageAccount.Credentials);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public Connection()
{
try
{
this.context = new UserDataContext(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);
this.context.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
}
catch (Exception ex)
{
throw new Exception("There was a problem trying to create the user. " + ex.Message);
}
}