In my Mongo db collection have 2 date fields TimeStamp, OpEndTime, I need to take order by OpEndTime-TimeStamp. It is working with a small amount of data. For huge data throw exception out of ram space. So need to create the index with difference of OpEndTime and TimeStamp. I don't know how to create it. I am using C# mongo db driver
I tried like below
DBContext.ClientDb.Repository(collection).Indexes.CreateOne(Builders.IndexKeys.Ascending(i =>i.OpEndTime- i.TimeStamp));
but am getting error like below
An exception of type 'System.InvalidOperationException' occurred in MongoDB.Driver.dll but was not handled in user code
Additional information: Unable to determine the serialization information for i => Convert((i.OpEndTime - i.TimeStamp)).
Related
I have created Web API core project and generated entity framework core related components as detailed in the article here
It generated all the entities properly, but few indexes were created with an extra column. Here is an example
entity.HasIndex(e => new { e.Column1, e.Column2, e.Column3 })
.HasName("ix_Table1_Column2_Column3");
In the above example, column1 is not actually part of index when i checked DB directly. I am puzzled as to what is causing this issue.
This presence of unwanted column is causing below exception.
An exception of type 'System.InvalidOperationException' occurred in
Microsoft.EntityFrameworkCore.dll but was not handled in user code
Additional information: The indexes {'Column1', 'Column2', 'Column3'}
on 'Table1' and {'Column2', 'Column3'} on 'Table1' are both mapped to
'able1.IX_Column2_Column2' but with different columns ({'Column1',
'Column2', 'Column3'} and {'Column2', 'Column3'}).
Any help is much appreciated. Thanks in advance!
Hey guys I am almost done with my CRUD project for my Database Project. I am just trying to finish up and complete the Delete Functionality.
query = string.Format("DELETE FROM customers WHERE `cid`= {0};", mDeleteTextBox);
My variable mDeleteTextBox is filled with the value I want.
What is wrong with my query?
ERROR MESSAGE
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.TextBox, Text: 6' at line 1
Your additional information says it all: you're trying to pass mTextBox as a parameter for your query, but in order to access the content of the textbox itself (which is the data you want to use to complete your query), you should access the Text property of the textbox.
So, your code:
query = string.Format("DELETE FROM customers WHERE `cid`= {0};", mDeleteTextBox);
became
query = string.Format("DELETE FROM customers WHERE `cid`= {0};", mDeleteTextBox.Text);
I am writing a C# application that reads from an XML file, converts that to JSON, and uploads to MongoDB. Some of our tags are structured with a period at the end, like so:
<BatteryTest.>GOOD</BatteryTest.>
Using the Newtonsoft library I am able to convert the XML to JSON without a problem. It is when I go to deserialize it to a BsonDocument that I have trouble:
var document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonText);
I get the following error message:
An exception of type 'MongoDB.Bson.BsonSerializationException' occurred in mscorlib.dll but was not handled in user code
Additional information: Element name 'BatteryTest.' is not valid'.
I have looked at the documentation but I haven't found anything that would explain how I can change the formatting properties of the deserializer. This is valid XML so I am not sure why the deserializer would choke on it, either.
Is this invalid JSON? If so, is there a way to still insert it into MongoDB without dropping that period?
As the the dot can be used in MongoDB queries, it can not be used in field names. You will have to preprocess the JSON before converting it into a BSONDocument.
So these days I am trying to work with the TFS API. So far it was good, but all of a sudden.. I want to retrieve specific story's work items and their respective information using a search by ID method to pick the correct story. In order not to miss some important information I am doing SELECT * in my queries. I get the story, I get the Tasks.. But there seems to be problem with few of the fields - namely AreaPath, IterationPath and Type. As a primitive check I've written down some Console prints to check what's good and what's not - so if I uncomment any of the three previously named on execution this exception is thrown: A first chance exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.FieldDefinitionNotExistException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll.
Here is what I am trying to print out:
Console.WriteLine(target.Fields["Title"].Value);
Console.WriteLine(target.Fields["Description"].Value);
Console.WriteLine(int.Parse(target.Fields["Id"].Value.ToString()));
Console.WriteLine(target.Fields["AreaPath"].Value); //Problem 1
Console.WriteLine(target.Fields["IterationPath"].Value); //Problem 2
Console.WriteLine(int.Parse(target.Fields["AreaId"].Value.ToString()));
Console.WriteLine(int.Parse(target.Fields["IterationId"].Value.ToString()));
Console.WriteLine(target.Fields["State"].Value);
Console.WriteLine(target.Fields["Type"].Value.ToString()); //Problem 3
With or without ToString() nothing really changes.
Any suggestions ?
EDIT: They are not null, I've checked while in Debug mode, they all have assigned values.
Use CoreField or builtin getters:
Console.WriteLine(target.Fields[CoreField.Title].Value);
Console.WriteLine(target.Fields[CoreField.AreaPath].Value);
Console.WriteLine(target.State);
Console.WriteLine(target.Type.Name);
I'm having a kind of bizzare issue while trying to filter results from Azure Table Storage by a DateTime field. I have two different queries for two diffferent tables with two different models. Both need to filter on a DateTime field but only one works, the other retuns an exception:
Microsoft.WindowsAzure.Storage.StorageException was unhandled by user code
HResult=-2146233088
Message=The remote server returned an error: (400) Bad Request.
Source=Microsoft.WindowsAzure.Storage
StackTrace:
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
The queries:
var fromDate = DateTime.UtcNow.AddDays(-14);
Working one:
from entity in AnalyticsStorage.ConversionTable.CreateQuery<ConversionAnalyticsModel>()
where entity.Date > fromDate
select entity
Not Working:
from entity in AnalyticsStorage.Table.CreateQuery<AnalyticsTableModel>()
where entity.ResponseTime > fromDate
select entity
I've made sure the the DateTime field is actually populated in the table. Commenting out the where makes the query run, though obviously that's not very useful.
Has anyone run into this? Are there gotachas in Azure Table Storage that I could be running into but can't see?
This is built against the current version of the Azure Storage DLL (3.0.3) and both queries are side by side in the same class, just in different methods.
I can't say I know why this is happening but after some time with Fiddler I figured out that it was using an anonymous type for the field name:
() gt datetime'2014-02-27T21:55:16.9605195Z'
Should be:
RequestTime gt datetime'2014-02-27T21:55:16.9605195Z'
Once I noticed this I wrote a query using the pre-LINQ syntax:
var query = new TableQuery<AnalyticsTableModel>().Where(
TableQuery.GenerateFilterConditionForDate(
"ResponseTime",
QueryComparisons.GreaterThan,
fromDate));
And this worked perfectly. So there seems to be a consistency issue with the current LINQ library that is causing it to not always map the field in the model to the field in the table. It could be that both RequestTime and ResponseTime are protected words to so my using their names is breaking the implementation without it properly warning me.