RealmMigrationNeededException in C# adding only one property - c#

I have an app that uses Realm db. I have added a string property to UserRealm named Test.
When I try to run my app it writes
Realms.Exceptions.RealmMigrationNeededException: Migration is required
due to the following errors:
- Property 'UserRealm .Test' has been added.
I'm trying to search on the internet, but almost everywhere the solution is deleting the old database. I dont want to delete the old database, I need to keep it and just add this one column.
This is a Xamarin/C# project.
How can I just simply add a sinle property migration to the realm? It's no problem if the default value is string.Empty.
I Use
Realm nuget 3.4.0,
Realm.Database 3.4.0
Fody 3.3.4

Just add a MigrationCallback to your RealmConfiguration, you do not have to do anything within that callback if no data transformation is needed and you do not need to init new properties to something other than their default values in Realm.
var config = new RealmConfiguration
{
SchemaVersion = 2,
MigrationCallback = (migration, oldSchemaVersion) =>
{
}
};
re: https://realm.io/docs/dotnet/latest#performing-a-migration

Related

acumatica c# / Add SOPackageDetailEx

I have this error when I try to add a line of package
Error : Another process has added the "SOPackagedetail" record. Your changes will be lost.
error
My c# code is this :
protected virtual void creationColis()
{
SOShipment ship=Base.CurrentDocument.Select();
SOPackageDetailEx colis = new SOPackageDetailEx();
colis.BoxID="COLIS";
colis.PackageType="M";
colis.ShipmentNbr=ship.ShipmentNbr;
SOShipmentEntry graph = PXGraph.CreateInstance<SOShipmentEntry>();
graph.Packages.Insert(colis); //insertion de l'enregistrement
graph.Packages.Update(colis);
graph.Actions.PressSave();
graph.Clear();
}
Do you know what I must to change please ?
Thanks so much
Xavier
Your question needs more context. For starters, where does your code reside? Given that you reference Base.CurrentDocument.Select, I'm going to assume you are extending SOShipmentEntry to add your code.
In this case, you would just use the Base.Packages view rather than initializing your own instance of SOShipmentEntry where your example goes into trying to use graph.Packages. Regardless, there are 2 parts here that need to be addressed.
Packages is not the primary view of SOShipmentEntry. When you create an instance of a graph, you must tell the graph what record is needed in the primary view. In your example where you create a new instance of a graph, you might do something like this:
graph.Document.Current = graph.Document.Search<SOShipment.shipmentNbr>(myShipmentNbr);
If you are working on a graph extension of SOShipmentEntry, then you probably don't need to create a new instance of the graph. Just make sure graph.Document.Current isn't null before you add your package record - see bullet 2.
Once you have a shipment selected, you can then insert your package information. However, the way you have done it here effectively is trying to add a random package to a null shipment (by the structure of the views) but forcing the record to attach to the right shipment by sheer brute force. The views don't like to work that way.
A better way to add your package once you have a current shipment (Document) is like this:
// Find the current shipment (from the primary view Document)
SOShipment ship = Base.Document.Current();
if(ship?.ShipmentNbr != null) {
// Insert a record into the Packages view of the current shipment and return the record into colis
SOPackageDetailEx colis = Base.Packages.Insert(colis);
// Set the custom values
colis.BoxID="COLIS";
colis.PackageType="M";
// Update the Packages cache with the modified fields
Base.Packages.Update(colis);
// If more fields need to be updated after those changes were applied, instead do this...
colis = Base.Packages.Update(colis);
colis.FieldA = ValueA;
colis.FieldB = ValueB;
Base.Packages.Update(colis);
// If a save is needed, now is the time
Base.Save.Press();
}
Notice that I didn't assign ShipmentNbr. That is because the DAC has that field defined to pull the ShipmentNbr from SOShipment through these 2 attributes.
[PXParent(typeof(FK.Shipment))]
[PXDBDefault(typeof(SOShipment.shipmentNbr))]
This means that when the record is created, Acumatica should lookup the parent SOShipment record via the Key and do a DBDefault on the field to assign it to the SOShipment.ShipmentNbr value (from the parent). Important side note: PXDefault and PXDBDefault are NOT interchangeable. We use PXDefault a lot, but off the top of my head I can't think of a case of PXDBDefault outside of defaulting from a database value like this specific usage.

Shared Variables in CRM 2011 Plugin

I am attempting to use the SharedVariable of the IPluginExecutionContext between different calls to the same plugin. I have the following scenario:
The user is attempting to create a new Entity Record and the plugin has been triggered on the Pre stage. Based on some logic, I am setting a SharedVariable like so:
var context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext));
context.SharedVariables.Add("MySharedVariable", true);
I then attempt to update other records of the same entity like so:
var qe = new QueryExpression("new_myentity");
qe.Criteria.AddCondition("ecs_myfield", ConditionOperator.Equal,"someValue");
var results = service.RetrieveMultiple(qe);
foreach (var foo in results.Entities)
{
//Do something to foo
service.Update(foo);
}
I also have a plugin registered for Update on the Pre stage, however, I want to check MySharedVariable and do something else based on whether or not it is set.
In the Update, the context does not contain the key for 'MySharedVariable'. I have confirmed this by using the ITracingService.
Is there some restriction on passing shared variables between plugins that are run on different records?
The plugin execution mode for both the Create and Update is set to Synchronous and as already explained, both are registered on the Pre Operation stage
I don't use SharedVariables often, but I'm sure they are available in the same Execution Context (for example from a Pre Event to a Post Event for the same message on the same record).
They can't be used to share values between different plugins on different messages on different records (as in your case: set the value inside the Create of one record and retrieve the value inside the Update message of a different record)
For your situation I think it is preferable to use a custom entity to store the values, or create an additional attribute to the entity.
Hi by looking at the scenario you explained.
I will not be able to test this my self. But If you change the Update plugin from Pre to Post.
If you change the update plugin from PRE-Operation to Post Operation. You will definitely get the SharedVariable in the execution context.
Pass Data Between Plug-Ins
CRM 2011 Plugins – Shared Variables

LightSwitch - "Reference properties cannot be set to deleted or discarded entities."

I am experiencing this exception when trying to define a data member contained within another piece of data.
Example:
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
newRecord.SubContainer = this.DataWorkspace.ApplicationData.SubContainers.AddNew();
The exception, "Reference properties cannot be set to deleted or discarded entities.", is encountered with the second line.
I don't understand what entity it's talking about with regard to it being discarded or deleted, so any help with this issue would be most appreciated.
The code lines are in an interface function defined in LightSwitch, which is called from a Silverlight project, passing data from that project to the LightSwitch project.
I eventually managed to do this after working out that I needed to be on the 'Logic' thread, which I was not. I spent a little while messing around trying to find a this.DataContext but could not (my Silverlight project had this but not the LightSwitch project).
Eventually though I found out what I needed to do:
this.Details.Dispatcher.BeginInvoke(() =>
{
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
newRecord.SubContainer = this.DataWorkspace.ApplicationData.SubContainers.AddNew();
newRecord.exampleIntProperty=2;
newRecord.SubContainer.innerString="Example";
});
I can then assign data to the properties of newRecord and the properties of the objects it contains (such as the example SubContainer's properties), although obviously the new record is not saved until LightSwitch is instructed to save its data.
Your code needs to be changed slightly:
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
SubContainer newSub = newRecord.SubContainers.AddNew();
If the navigation property isn't called SubContainers, just replace that with the correct name.

Update() not working in MongoDB

MongoDB for C#, I started following their tutorial but the compile error I get is on this line:
http://www.mongodb.org/display/DOCS/CSharp+Driver+Quickstart
var update = Update.Set("Name", "Harry");
saying
System.Windows.Forms.Control.Update()' is a 'method', which is not
valid in the given context.
The only difference I see is that they have used a Console Application but I created a C#WinForms applications and pasted their code inside a button click .
Update is simply ambiguous in the context you are using the call. You need to qualify the Update statement to include the namespace it is in.
var update = MongoDB.Driver.Builders.Update.Set("Name", "Harry");
This will probably get annoying, so you can also create an alias in your header.
using U = MongoDB.Driver.Builders.Update;
Then, you can change your statement to be this:
var update = U.Set("Name", "Harry");
I guess your c#WinForms contains an method called Update, which c# tries to access instead of the MongoDB one. Have you checked that you're imported everything needed and that your accessing the right Object?

Orchard: New widget isn't available to be added to zone

I'm working with Orchard 1.1.30
I created a MapPart per this Orchard documentation link, then converted it to a widget by this link. The first creates a content part that can then be included with different content types. This behaved as expected. The second procedure converts that content part to a widget. The first procedure is, more or less, a pre-requisite for the second.
The Maps module compiles, but when I attempt to add a widget to any zone, the Map widget is not even an option. I understood it would become an option after adding this migration:
public int UpdateFrom1()
{
// Create a new widget content type with our map
ContentDefinitionManager.AlterTypeDefinition("MapWidget", cfg => cfg
.WithPart("MapPart")
.WithPart("WidgetPart")
.WithPart("CommonPart")
// Shouldn't this behavior create an available widget?
.WithSetting("Stereotype", "Widget"));
return 2;
}
The UpdateFrom1 update was successful--still too new at Orchard to guess what might be happening.
This was solved by running the migration again, only naming it UpdateFrom2 and returning 3. Reporting indicates this migration was run both times, but only the second time produced the desired results.
Something must have changed between the first migration and the first attempt to add the widget to a zone???

Categories