TempData["Amalgamation"] = SearchList;
I am using this code already in this TempData a record is there now i want to append new data which was stored in "SearchList". How can i do that?
Assuming SearchList is a List<T>
var searchList = (List<SomeType>)TempData["Amalgamation"];
searchList.Add(...);
Related
I have an array of Strings which represent Firebase Document IDs like so:
var idArray = [“PuLDb90jgz3a5P8bLQoy”, “PMKoZIp46umXQnUlA64a”, “cVGbD3Wy4gWjZ9fZP7h1”]
This Array is dynamic and has been generated by a previous getDocuments call. It could have up to 15 ID strings in it, so it cannot be hard coded.
Within each Firebase Document I have an Int field called menuPosition set to a current value.
What I am trying to do is update each document which appears in the idArray and simply -1 from the menuPosition field value in one go.
What should be so straightforward is driving me crazy - does anyone know a simple way to do it? Obviously, if I put it in a for loop then the code will run too many times and my menuPosition value would be wrong. I just want each operation to perform once.
Any help would be greatly appreciated
Just run a loop over the document IDs and decrement the field in each iteration.
var idArray = ["J2LovReBF0v8F4e0RSBU", "UcW8tsgld2ZuUo92xfP8", "oHTJ4iO1NWCK7x1aryne"]
for docId in idArray {
Firestore.firestore().document("someCollection/\(docId)").updateData([
"menuPosition": FieldValue.increment(Int64(-1))
])
}
If you want this operation to be atomic then just wrap it in a batch write.
var idArray = ["J2LovReBF0v8F4e0RSBU", "UcW8tsgld2ZuUo92xfP8", "oHTJ4iO1NWCK7x1aryne"]
let db = Firestore.firestore()
let batch = db.batch()
for docId in idArray {
batch.updateData([
"menuPosition": FieldValue.increment(Int64(-1))
], forDocument: db.document("someCollection/\(docId)"))
}
batch.commit()
In sitecore, when getting the datasource from the renderingcontext, it returns a guid. Is there a means to convert this to the actual string value stored in the datasource field.
I want to run a "fast" query but need the path stored in the rendering context datasource instead of the guid.
Thanks,
If what you receive is a Guid, you can use
var idString = guid.ToString("B");
if what you receive is Sitecore.Data.ID, just use:
var idString = id.ToString();
The guid that you are getting is the Sitecore ID of the datasource item. You should be able to get it's path directly:
var dataSource = Sitecore.Context.Database.GetItem(RenderingContext.CurrentOrNull.Rendering.DataSource);
var dataSourcePath = dataSource.Paths.Path;
I have Realm data model
import RealmSwift
class Priority: Object {
dynamic var id = ""
dynamic var text = ""
dynamic var time = ""
}
And I can get all the stored objects
let realm = try! Realm()
let objects = realm.objects(Priority)
How to move an object from the index 7 in the index 3 and save the table?
Objects stored in a Realm are unordered. If you want to store an ordered list of objects you can do so using a List<T> property on a model class. List provides mutation methods that can be used to change the order of objects within the list.
You can put the Objects in Realm List, then you can use both move and swap methods to reorder.
Here is the List API: https://realm.io/docs/swift/latest/api/Classes/List.html
I want fetch the details of a Collection in Odata services like the following URL
http://my.company.com/odata/Employee('1234')/Details
I tried with the following code to do so. Not sure whether fromEntityKey is the right thing to do or anything else.
manager = new breeze.EntityManager(collectionData.serviceName);
var empType = manager.metadataStore.getEntityType("Employees");
var entityKey = new EntityKey(empType, '1234');
var query = EntityQuery.fromEntityKey(entityKey);
But it gives me an error "Be sure to execute a query or call fetchMetadata first."
I also tried that from this link. But I'm still getting the same.
Can any one help me on this?
You can't use manager.metadataSote.getEntityType("Employees") until metadata has been retrieved from the server. By default this occurs during the first query operation, but your code is attempting to use the metadata before it has been retrieved.
Also, I think that you are confusing the name of your resource "Employees" with the type of the instances returned by your resource, probably "Employee". I would also check whether your key's datatype is numeric or a string. The example below assume its numeric (unlike your example where the datatype of the key is presumably a string because you are quoting it).
So you have two approaches, either force the metadata to be fetched before you compose your query, like this:
manager = new breeze.EntityManager(serviceName);
manager.fetchMetadata().then(function () {
var empType = manager.metadataStore.getEntityType("Employee");
var entityKey = new EntityKey(empType, 1);
var query = EntityQuery.fromEntityKey(entityKey);
// if you want to also see the queries details
query = query.expand("Details");
return manager.executeQuery(query);
}).then(function (data) {
var results = data.results;
ok(results.length === 1, "should have returned a single record");
var emp = results[0];
));
or if you know the string name of the 'key' ("Id" in the example below) field, use it directly
manager = new breeze.EntityManager(serviceName);
var query = EntityQuery.from("Employees")
.where("Id", "==", 1)
.expand("Details");
manager.executeQuery(query).then(function(data) {
var results = data.results;
var emp = results[0];
});
I have a object with a lot of properties on it. A bunch of these large object are to be inserted in the db but with only one property on them changing. The property that will be changing is not the primary key. First time SaveChanges succeeds but the subsequent ones fail with "An object with the same key already exists in the ObjectStateManager.....". Here is the flow in code:
//create the entity and set the properties that don't change
TheLargeObject obj = new TheLargeObject();
obj.Prop1 =
obj.Prop2 =
...
obj.Prop20 =
//create a list of values that differ between each entity
List<int> validIds = new List<int>();
private static void SaveToDatabase(TheLargeObject obj, List<int> validIds)
{
foreach (int id in validIds)
{
//this is the only property that changes
obj.KeyId = id;
//make a copy - do we really need this?
TheLargeObject newobj = new TheLargeObject();
newobj = obj;
using(Entities objContext = new Entities())
{
objContext.TheLargeObjects.AddObject(newobj); //ERROR: An object with the same key already exists in the ObjectStateManager.
objContext.SaveChanges();
}
}
}
I'm just starting out with EF4, so I'm probably going about this in the wrong way.
Thanks
I'm not sure what your trying to do here. Mainly this statement confuses me:
A bunch of these large object are to be inserted in the db but with only one property on them changing.
How can a new object (ie inserted) be changing? If it's new, what is there to change?
All of the entities in your model have an EntityKey, which is usually the primary key on the database-side.
What i think your doing is doing .AddObject, when you should be doing .Attach.
Here's how you INSERT a new object:
var newFoo = new Foo();
ctx.Foos.AddObject(newFoo);
newFoo.SaveChanges();
Here's how you UPDATE an existing object:
var existingFoo = ctx.Foos.SingleOrDefault(x => x.Id == 1); // or however you want to get it
existingFoo.Name = "Changed foo";
newFoo.SaveChanges();
Or if you have a detached entity:
var existingFoo = new Foo();
existingFoo.Name = "Foo name";
ctx.Foos.Attach(existingFoo);
ctx.SaveChanges();
So, i think in your example, your code should simply be:
objContext.TheLargeObjects.Attach(newObject);
objContext.SaveChanges();
In a nutshell, if you have an entity which you are positive already exists in the database, and you have constructed the entity manually, use .Attach. If you have a brand spanking new object, use .AddObject.
However, to be safe - you could go and get the object again, make the changes you need, then do .SaveChanges().
.Attach is usually used in stateless scenarios such as web sites, where objects are not kept in the graph between requests, therefore to make changes we need to .Attach, or retrieve the object again before making the changes.
Hopefully this clears it up for you.