I am facing an issue while inserting an entity. I am not sure what is wrong in there.
As I insert, I get an StorageClientException stating "value out of range".
My Table Service Entity looks like
public class Itinerary : TableServiceEntity
{
public string Name { get; set; }
public DateTime DOB { get; set; }
public int Sex { get; set; }
public string ToPNR { get; set; }
public string ReturnPNR { get; set; }
public string ContactNumber { get; set; }
public DateTime TravelDate { get; set; }
public DateTime ReturnDate { get; set; }
}
The entity gets inserted when the complete itinerary details are provided, but for itinerary having only one side details, the insert method gets failed with the given exception.
Any help would be appreciated.
The problem I guess lies with your DateTime fields. If you haven't initialized them before storing your data in the Table Storage, then the values that will be assigned to these fields will be that of .NET DateTime.Min value. Unfortunately this value is out of bounds of Azure Table Storage. Hence it is always advisable to provide some value to your DateTime field in the Azure Table Storage. In case, you want to assign a default value to the same, use the CloudTableClient.MinSupportedDateTime property. This will initialize the field with the min value supported by Azure Storage -
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudtableclient.minsupporteddatetime.aspx
Hope this helps
Related
I'm looking for a way to map several POCO objects into single table in the ServiceStack.
Is it possible to do this in a clean way, without "hacking" table creation process?
As a general rule, In OrmLite: 1 Class = 1 Table.
But I'm not clear what you mean my "map several POCO objects into single table", it sounds like using Auto Mapping to populate a table with multiple POCO instances, e.g:
var row = db.SingleById<Table>(id);
row.PopulateWithNonDefaultValues(instance1);
row.PopulateWithNonDefaultValues(instance2);
db.Update(row);
If you need to maintain a single table and have other "sub" classes that maintain different table in the universal table you can use [Alias] so all Update/Select/Insert's reference the same table, e.g:
public class Poco
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
[Alias(nameof(Poco))]
public class PocoName
{
public int Id { get; set; }
public string Name { get; set; }
}
[Alias(nameof(Poco))]
public class PocoAge
{
public int Id { get; set; }
public int Age { get; set; }
}
Although I don't really see the benefit over having a single table that you use AutoMapping to map your other classes to before using that in OrmLite.
I'm very new to Entity Framework, so I apologize if this is a stupid question...
Here is my POCO:
[Table("RegistrationCodes")]
public class RegistrationCode
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public Guid Code { get; set; }
public int? UserId { get; set; }
[ForeignKey("UserId")]
public UserProfile User { get; set; }
[StringLength(500)]
public string Notes { get; set; }
}
When I retrieve the object from my DBSet with the code below, UserId is always null.
return this.Context.RegistrationCodes.FirstOrDefault(c => c.Code == code);
I've checked the database and verified that the UserId is not null. Additionally, i have profiled and can see that the UserId is being requested from the database.
Any help would be greatly appreciated.
Ohhhhh my, don't I feel stupid...
Here's what was happening, I run the code and I can see the UserId field is updated in the database. Every time I restart the application, code migrations would run add do an AddOrUpdate to the table which would null out the UserId column.
Can we just delete this question all together?
My project is the throwing the above error because the Ship Date in my table is null. I am using Code First, and the DateTime field is declared as nullable both in the generic set and the SQL table. I am populating a gridview with the result set. Ideally, I would like to have the gridview display "not yet shipped" when the ShipDate field is null, but at this point, I would be happy just to be able to display the record. Any help is greatly appreciated. Here is the code-behind and the context class that I am using:
public class Order
{
[Key]
public int OrderID { get; set; }
public int CustomerID { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipState { get; set; }
public string ShipZip { get; set; }
[ScaffoldColumn(false)]
public string PaymentTransactionID { get; set; }
[ScaffoldColumn(false)]
public System.DateTime OrderDate { get; set; }
public System.DateTime? ShipDate { get; set; }
public virtual Customers Customers { get; set; }
public List<OrderDetail> OrderDetails { get; set; }
}
The code behind is:
public List<OrderDetail> FetchByOrderID()
{
int myOrderID = CusOrderId;
ProductContext db = new ProductContext();
return db.OrderDetails.Where(
c => c.OrderID == myOrderID).ToList();
}
I was getting the above error when trying to get the max(date_column) through LINQ. The column was defined as NOT NULL and when there are no rows returned in the query its trying to assign null to the DateTime property that's representing the date column. One solution is to change the date column to being NULLable which will create the entities property as type DateTime?
I use VB.Net, but had a similar problem. I do not know if you fixed your problem.
But I declared the variable as Nullable(Of Date) and that did the trick to me. I am told that adding the "?" does the similar thing, but unfortunately did not work out for me, or I did not do it correctly. :o)
private DateTime? _settlementDate {get;set;}
I was having a similar problem, same error.
Turns out I failed to setup my ConnectionString in the configuration.
I am trying to serialize an object to Azure Mobile Services.
The object contains an array of a second object which should also be serialized.
[DataContract()]
class ObjectA
{
[DataMember(Name= "id")]
public int Id { get; set; }
[DataMember(Name = "info")]
public string info{ get; set; }
[DataMember(Name = "collectionOfB")]
public ObjectB[] myArrayOfB{ get; set; }
}
[DataContract()]
class ObjectB
{
[DataMember(Name= "id")]
public int Id { get; set; }
[DataMember(Name = "info")]
public string info{ get; set; }
}
I have loaded both table's properly and can insert an individual item into each of the tables.
However when I call the InsertAsync method on the table for objectA I receive an error
Cannot serialize member 'myArrayOfB' of type 'namespace.ObjectB[]' declared on type 'ObjectA'
Any idea's on what I need to do to fix this?
Mobile Services doesn't support serialization of arrays. There are two good posts here that show how you might support this:
http://blogs.msdn.com/b/carlosfigueira/archive/2012/08/30/supporting-arbitrary-types-in-azure-mobile-services-managed-client-simple-types.aspx
http://blogs.msdn.com/b/carlosfigueira/archive/2012/09/11/supporting-complex-types-in-azure-mobile-services-clients-implementing-1-n-table-relationships.aspx
I am attempting to update an entry in Azure Table Storage. The function is:
public void SaveBug(DaBug bug)
{
bug.PartitionKey = "bugs";
bug.Timestamp = DateTime.UtcNow;
if (bug.RowKey == null || bug.RowKey == string.Empty)
{
bug.RowKey = Guid.NewGuid().ToString();
_context.AddObject(c_TableName, bug);
}
else
{
_context.AttachTo(c_TableName, bug);
_context.UpdateObject(bug);
}
_context.SaveChanges();
}
If it is a new entry (the "bug.RowKey == null" path), then it works fine. If it is an update to an existing entity, then the "AttachTo", and the "UpdateObject" calls work, but when it gets to "SaveChanges", it throws the "One of the request inputs not valid" exception.
The class that is being stored is:
[DataContract]
[DataServiceKey("RowKey")]
public class DaBug
{
[DataMember]
public bool IsOpen { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public string Description { get; set; }
[DataMember]
public string SubmittedBy { get; set; }
[DataMember]
public DateTime SubmittedDate { get; set; }
[DataMember]
public string RowKey { get; set; }
public DateTime Timestamp { get; set; }
public string PartitionKey { get; set; }
}
Does anyone know what the problem is?
Thanks for any help.
In case anyone is looking for the answer:
http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/0c9d476e-7970-422a-8b34-e987e41734df
Working through the table context, I had to change the call from:
_context.AttachTo(c_TableName, bug);
to:
_context.AttachTo(c_TableName, bug, "*");
You can also get this error if you mistakenly set the RowKey to a value you've already used (not that you'd get this problem with code in the question). I tried to push 50+ entities in one go and accidentally had the RowKey set to the same value for two of the entities.