Xamarin c#: Parse.com relation table seems to only work one way? - parse-platform

I'm working with Xamarin in Visual Studio.
I'm utilizing Parse (via SashiDo.com) and I'm trying to create a relation between my Users and the ParseObjects in a table called called Dispatch, like so:
//Make the new Dispatch object
var parseDispatch = new Parse.ParseObject("Dispatch");
//Save it
await parseDispatch.SaveAsync();
//...Setting various properties on the Dispatch object...
//Get a list of users (via another method)
IEnumerable<ParseUser> usersToLink = UsersToLinkToDispatch(); //And have verified elsewhere that this indeed returns a collection of ParseUsers
//Go through the users collection
usersToLink.ToList().ForEach( async (user) => {
//Get or create the dispatches-tracking relation for this user
var dispatchObjectRelation = parseDispatch.GetRelation<ParseObject>("DispatchesTracked");
//Add the current user to that tracker relation
dispatchObjectRelation.Add(user);
//save the dispatch to update the relation
await parseDispatch.SaveAsync();
});
So, when I go to inspect my tables in SashiDo, if I look at the Dispatches table, I see a proper-looking relational link, and if I click on that link, I see the list of linked Users. So far so good, right?
But if I look at the Users table, while there also seems to be a proper-looking relational link, when I click on it I do not see a list of linked Dispatches.
Is this expected behavior, or is this apparent one-way-ness of the relational link an error?

Related

Entity being tracked despite AsNoTracking

I have an object, Client, with a navigation property that is a list of Order objects. Whenever I retrieve a Client object, I include the list of Orders, with AsNoTracking().
public new IQueryable<Client> FindByConditionNoTracking(Expression<Func<Client, bool>> expression)
{
return this.ClientContext.Set<Client>().Include(s => s.Orders)
.Where(expression).AsNoTracking();
}
In my UpdateClient repository method, I take in a Client object. I then attempt to retrieve that original client from the database (using Include to get the child Orders), map the Client param to the original, and save to the database. Over here, I do not use AsNoTracking, because I specifically want the changes to be tracked.
public new void Update(Client client)
{
var id = client.ClientId;
var original = this.ClientContext.Clients.Include(s => s.Orders).Where(s => s.ClientId == id)
.FirstOrDefault<Client>();
original = _mapper.Map(client, original);
this.ClientContext.Update(original);
}
The error I am getting is that an instance of Order with the same key value is already being tracked. A few problems with that:
Wherever the Client and the child Orders are retrieved for the purposes of display I use AsNoTracking.
The only place where I retrieve without AsNoTracking is where I get the original within this very method.
The bug isn't with the parent property. If I was improperly retrieving the Client elsewhere, wouldn't I have this error with the Client id itself? But the error seems to be only with the navigation property.
All insight is appreciated!
If anyone else runs into this: Automapper, when mapping collections, apparently recreates the entire collection. I solved the above issue by using Automapper.Collections in my mapping configuration. Thanks to Mat J for the tip!

Ms Bot Builder : How to create a hierarchical library structure?

Let's say I create a library shop and add to my bot :
dialogs/shop.js
var lib = new builder.Library('shop');
lib.dialog('car', function(session){})
module.exports.createLibrary = function () {
return lib.clone();
};
bot/index.js
bot.library(require('./dialogs/shop').createLibrary());
So I can trigger the car dialog through session.beginDialog('shop:car').
I'm looking to create a library for each category of items to shop so car comes within vehicle library and I get to call the car dialog through session.beginDialog('shop:vehicle:car')
I tried doing this :
var lib = new builder.Library('shop');
var lib_vehicle = new builder.Library('vehicle');
lib_vehicle.dialog('car', function(session){})
lib.library(lib_vehicle.clone());
module.exports.createLibrary = function () {
return lib.clone();
};
bot.library(require('./dialogs/shop').createLibrary());
But this triggers car dialog through session.beginDialog('vehicle:car') instead of session.beginDialog('shop:vehicle:car')
How do I achieve a hierarchical relationship between libraries?
Thanks
After looking at the source code, the SDK isn't set to handle hierarchical structures in this situation you described.
When dealing with 'vehicle:car', it generates an array and takes the library name and the dialog id. The session method findDialog() (called inside of beginDialog) is hardcoded to only accept one id, so 'car', and everything works fine. For 'shop:vehicle:car', 'car' is essentially left in the dust, and your chatbot goes to look for a dialog with an id of 'vehicle' in the library 'shop'.
Edit: If you think it's a feature worth exploring, file a [Feature Request] issue in the BotBuilder repo so a discussion can ensue.

Getting objects from Parse Relation that were added in this save

I have a Parse Class Group and there is a parse relation field in it, called people (users, who are in this group). I am implementing a afterSave on "Group". I want to notify users, who are just added by admin into this group.
How do i do that ?
Parse.Cloud.afterSave(Group, function(request){
Parse.Cloud.useMasterKey();
var group = request.object;
var relation = group.relation("people");
//How to get users that are added on this save.
});
To find the new records being added to a relation, you need to inspect the relationsToAdd property of a Relation (its an array):
var newRecords = request.object.op("people").relationsToAdd;
I know this works in beforeSave but have not used it in afterSave tirggers

ReactiveUI - ReactiveCommand to get more data for objects in ReactiveList

Currently I am learning ReactiveUI and I am not sure how to approach this problem. What I want to achieve is once a reactive list has been loaded (in this case I am using a command to load it from a local store) I want to be able to trigger that each of the items in the reactive list then go off and fetch data from an api endpoint and update the view model.
What I currently have to load and create the view models using this logic:
LoadSavedLocations = ReactiveCommand.CreateAsyncTask(async o => {
var savedLocations = await _savedLocationService.GetUserSavedLocations();
return savedLocations;
});
LoadSavedLocations.Subscribe(savedLocations =>
{
foreach (var savedZone in savedLocations)
{
Zones.Add(new ZoneDetailViewModel() {
ZoneId = savedZone.ZoneId,
SavedName = savedZone.SavedName,
});
}
});
I want to then be able to have a command that I can kick off (one first load of the screen and then when the user prompts for an update - pull for reload).
There are two ways I think I can do this but struggling with the approach and the code to achieve this.
Option 1
A command which loops through the items in the ReactiveList fetches data from the Api and then updates that viewmodel something along the lines of
UpdateZones = ReactiveCommand.CreateAsyncTask(async o =>
{
foreach (var zone in Zones)
{
// Fetch
// Await
// Update view model
}
return null;
});
With this I am confused around what the return type of the command would be just a new object()? Is there a better way than just looping like this?
Option 2
On the view model ZoneDetailViewModel have a command called FetchExtraData which will then return the data from the API and I can subscribe to that command in the view model and populate the extra properties. With this approach how does the parent viewmodel trigger all the items in the ReactiveList to fire their commands.
For both approaches I don't know how to get each of the items in the ReactiveList to do logic which involves going to an Api and update.

reading related data after a selection of a foreign key - MVC3 and EF4

I am new to MVC and EF and I have a question.
I have built a site with models views controllers etc.
On an edit view for a Case (pretty big model so I won't post it here) I have a FK to a Customer model using CustomerID. When a user selects a customer id from a drop down list, I would like to display CustomerName, CustomerPhone etc after the selection of the ID. I think I might need to do a post back for this to work?
Also, do I need to Include the related entities as part of the initial data "get"? I have read some detail on that but I dont fully understand how that needs to work.
Please let me know if I should post more info. Thanks!
Here is my ActionResult for Edit
public ActionResult Edit(int id)
{
Cases cases = db.Cases.Find(id);
//related data needs to loaded to show related data fields
//include related data entities
var v = db.Cases.Include("Customers");
ViewBag.TechnicianID = new SelectList(db.Technicians, "TechnicianID", "LastName", cases.TechnicianID);
ViewBag.BranchID = new SelectList(db.Branches, "BranchID", "BranchName", cases.BranchID);
ViewBag.EngineModelID = new SelectList(db.EngineModels, "EngineModelID", "EngineModelName", cases.EngineModelID);
ViewBag.CaseCategoryID = new SelectList(db.CaseCategories, "CaseCategoryID", "CategoryName",cases.CaseCategoryID);
ViewBag.Qualified = new SelectList(new[] { "YES", "NO", "PARTIALLY" });
ViewBag.CaseStatus = new SelectList(new[] { "OPEN/IN PROCESS", "CLOSED" });
return View(cases);
}
The line
var v = db.Cases.Include("Customers")
is what I am trying to use to load related customer data and then show in my edit view like this:
#Html.EditorFor(model => model.Customer.CustomerName)
Well it depends on what you are trying to do. You could include a model which holds all the required data and send it with every call on that page (initial empty ofcourse)
Once you selected the customer, do post-back and send the customerId to your application and return the same page with the desired model.
You could do that via AJAX too.
Also, do I need to Include the related entities as part of the initial data "get"?
Not sure if I understand what you are trying to say. You mean that you think you would have to send all customer's data down to the page and select the related data on client side?

Resources