NoRM UpdateOne no work - c#

I'm using NoRM + MongoDB in an application test. I found the source code of the Mongo Session http://normproject.org/samples where the method update wrapp this:
using(var db = Mongo.Create(_connectionString))
{
db.GetCollection<T>().UpdateOne(item, item);
}
But when I send object to update using this method my object no save, but what if I call Save instead of UpdateOne my object is save.
My objects: https://gist.github.com/1616565
What's wrong?

Hopefully this helps:
http://groups.google.com/group/norm-mongodb/browse_thread/thread/8ba8b462b6fe16a5/a4bfaecef4b1cbfc?lnk=gst&q=Update#a4bfaecef4b1cbfc
Anup

I would recommend using the official C# driver, which you can find at:
http://www.mongodb.org/display/DOCS/CSharp+Language+Center

Related

xamarin.android save List<MyClass> in OnSaveInstaneState

I am trying to do a "ToDoListApp" and my problem is that when I add some tasks to do and then close the app everything is deleted and the app starts anew.
I saw some other similar questions and it seems the solution is OnSaveInstanceState(Bundle outState) but I have a generic list with a class that I made List<MyClass>. My Problem is that when I write outstate.Put… there is no option for my array I can only choose between int, string, charsequence and parcelable. So my question is how can I save the state of my app?
What you are trying to do here is a thing you should be doing using an SQLite mobile database instead, Can be done like so :
Download the NuGet package sqlite-net-pcl by Frank A. Krueger
Using SQLite, Create a SQLite connection object
var db = new SQLiteConnection (dbPath);
After you have established a connection create your table something like this :
db.CreateTable<MyClass>();
Then insert the data that you want to insert into to the table something like this:
db.Insert(_yourClassObject);
Retrieve Data something like this;
var stock = db.Get<MyClass>(**yourPrimaryId**); //single object based on condition
var stockList = db.Table<MyClass>(); //The list of all data in this table.
For a better understanding of how it works refer this
Update
If you want to do it using shared preferences the way to do it would be converting it to JSON and then storing it to preferences as a string something like this:
Using Newtonsoft JSON package:
List<MyClass> your_Object;
your_Object=FooValueAssigned;// Assumed assignment
string yourString=JsonConvert.SerializeObject(your_Object); //It accepts any object in your case give your list here
Now Save it in shared preferences like this:
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
ISharedPreferencesEditor editor = prefs.Edit ();
editor.PutString("your_list", yourString);
// editor.Commit(); // applies changes synchronously on older APIs
editor.Apply(); // applies changes asynchronously on newer APIs
Retrieve from shared preferences something like this:
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
string mString = prefs.GetString ("your_list", <default value>);
Convert it back to your object type something like this:
var yourObjectFromPref= JsonConvert.DeserializeObject<List<MyClass>>(mString);

implementing maxmind's free GeoLiteCity DB on a C# webform?

Has anyone successfully utilized MaxMind's data and C# code on a webform? I would appreciate any insight. If you can provide a walk through of the implementation process and perhaps some sample C# code that works for you, I would truly appreciate it.
Implementing max-mind is very simple, in C# we have Nuget package for max-mind Db reader
Install-Package MaxMind.GeoIP2 -Version 2.6.0
After that you can use max-mind db reader to read your db.
Finally take the read data as an object and obtain the details you want.
Example:
string path = #"c:\MaxMindDb\GeoIP2-City.mmdb";
using (var reader = new Reader(path, MaxMind.Db.FileAccessMode.Memory))
{
var data = reader.Find(ip).ToString();
var GeoData= JToken.Parse(data);
string CountryCode = GeoData["continent"]["code"].ToString() ?? null;
...

DynamicsCrm - Retrieve Multiple is not supported

I´m developing a data-extraction tool that gets data out of DynamicsCrm.
I have a few tables tough where i get the following exception:
Additional information: The 'RetrieveMultiple' method does not support entities of type 'mailboxstatistics'.
Reading online, using fetchxml is supposed to be the solution.
For me, it looks like i´m already using fetchxml.
My code:
private static EntityCollection RequestEntityCollection(String FetchXML, Microsoft.Xrm.Client.CrmConnection c)
{
using (OrganizationService service = new OrganizationService(c))
{
EntityCollection r = service.RetrieveMultiple(new FetchExpression(FetchXML));
return r;
}
}
I´m currently using the CRM2013 SDK so EntityCollection is from the Microsoft.Xrm.Client.dll in v6.0.0.0.
Also the documentation is using the RetrieveMultiple method.
Do you have some suggestions or is this not supported and the online suggestions are misleading?
Thank you!
The message is a bit misleading.
You get that error with MailboxStatistics because the entity is for internal use only.

How do you actually implement the Search Contract? (C#)

I'm having some trouble understanding and getting the search contract to work in my Store app. I have been unable to find any sort of documentation or guide that explains the structure of using the contract. (I've looked at the quickstarts on MSDN, the Search Contract sample and the build video, but that only really deals with javascript)
So far I've been able to run a query and get a list (of Custom Objects) into my search contract page, and from there I try to assign that to defaultviewmodel.results, but no matter what query I type nothing shows up I on the page. Is there something else I need to set?
What I have so far is as follows (excerpts):
App.xaml.cs
protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
{
SearchCharmResultsPage.Activate(args.QueryText, args.PreviousExecutionState);
SearchCharmResultsPage.ProcessSearchQuery(args.QueryText);
}
public async static void ProcessSearchQuery(string queryString)
{
try
{
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("recipeCustomObject Debug.WriteLine("Database exists, connecting");
SQLiteAsyncConnection connection = new SQLiteAsyncConnection("CustomObject_db");
List<CustomObject> resultsList = new List<CustomObject>();
string query = "SELECT * FROM CustomObjectDB";
resultsList = await connection.QueryAsync<RecipeRecord>(query);
}
catch (FileNotFoundException fnfExc)
{
Debug.WriteLine("FNFEXC: " + fnfExc.ToString());
}
}
I think it is possible that here lies the problem, though I'm not sure if it is, or how to change it.
the resultsList list is created here, but because the method it asynchronous, I can't return from the method. Because of this I'm guess that when I try to assign this.DefaultViewModel[Results] = resultsList; in the LoadStateMethod, the object doesn't exist (thought the program throws no error). When I try to add the same line in the ProcessSearchQuery method, i'm told that this is not valid in a static method, but I think I need the method to be static? My problem might just be a fundamental logic error?
Finally got it! found the solution here: http://jeffblankenburg.com/2012/11/06/31-days-of-windows-8-day-6-search-contract
For those looking for an answer in the future, the key is to make sure you have your search logic within the Filter_SelectionChanged method, which was something I wasn't doing. Look at the guide within the above link to get an idea of the structure.
Have you looked at the Search contract sample on the developer center? There's a C#/XAML version there as well.
My open source Win8 RSS Reader framework implements Search (and Share) have a look at the source and if you still got questions, I'll be happy to help http://win8rssreader.codeplex.com/

Subsonic: Using SharedDbConnectionScope together with TransactionScope seems to be broken

Using the code below, the expected behavior is that the database won't reflect the update since ts.Complete() is never called but the updates seems to go through. But if I leave out the SharedDbConnectionScope then the expected behavior is seen. Is there a problem with SharedDbConnectionScope? Btw I am using Subsonic 2.2
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
using (TransactionScope ts = new TransactionScope())
{
// update here
}
}
Found out the problem. The docs on Subsonic appears to be wrong. If I wrap TransactionScope over SharedDbConnectionScope then it works fine. The right way should be:
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
// update here
}
}
Edit: As mentioned by firestorm, SharedDbConnectionScope doesn't seem to work in Subsonic 2.2. So the only solution seems to be to install MsDts and don't use SharedDbConnectionScope.
I don't think SharedDbConnectionScope works at all in Subsonic 2.2.
The whole idea as far as I can see with the object is that when you use it you don't need to have MsDts installed on the server. I couldn't get this to work at all!
When you install MsDts then you don't need SharedDbConnectionScope any more that's why your code works when it gets created after TransactionScope.

Categories

Resources