Message 1 of 11
storing entities out of a transaction scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello every one
I remember @_gile once told me about not keeping a database resident entity out of the scope of a transaction. it was long time ago and Im not even sure if it was an advise for a special condition or in general.
I have a couple of objectIds stored in an objectId collection. they are determined before a jig runs.
then since I cant use ed.SelectWindow(), @norman.yuan suggested to check if those entities are inside the window or not and mimic ed.SelectWindow() this way.
his idea works perfectly good. but my jig is too slow and I feel its most likely because of casting objects using transactions. so instead of casting object ids to entities, can I store a list of those entities?
for example, does this code cause any issues?
public class ListSpecialEntities
{
public List<Entity> Result;
public void GetSpecialEntities()
{
var doc = ACAD.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var pso = new PromptSelectionOptions();
pso.MessageForAdding = "Select some Entities";
var sset = ed.GetSelection(pso);
if(sset.Status==PromptStatus.OK)
{
using (var tr = doc.Database.TransactionManager.StartOpenCloseTransaction())
{
foreach(ObjectId id in sset.Value.GetObjectIds())
{
Result.Add(tr.GetObject(id,OpenMode.ForRead) as Entity);
}
}
}
}
}
public class UseThoseEntities
{
public ListSpecialEntities _ents;
public UseThoseEntities(ListSpecialEntities lst)
{
_ents = lst;
}
public void ProcessThoseEntities()
{
foreach(Entity ent in _ents.Result)
{
//do some stuff
}
}
}