This project has moved. For the latest updates, please go here.

Deleting objects

Oct 8, 2013 at 7:52 PM
I know that the following code will delete an object:

var country = Data.Instance.Context.Countries.FirstOrDefault(d => d.Id == id);
Data.Instance.Context.DeleteObject(country);
Data.Instance.Context.SaveChanges();

However, the next time I query the Countries collection, I find that the element with that id is still in the Countries collection, all be it with its properties set to their default values.

So does DeleteObject really delete the object completely? Or just blank it? Does that mean that deleted objects could be re-used?

Does compacting the data store clear these blanked objects from the store?

Thanks

Regards
Kevin
Coordinator
Oct 9, 2013 at 7:44 AM
Hi Kevin,

That sounds like a bug, once the Country entity is deleted it shouldn't show up in a subsequent linq query. Are you on the 1.4 release ? There was a fix for another entity deletion issue in that release and I wonder if I may have introduced a regression bug. I'll see if I can replicate the bug - I assume that it will show up in the following:

var country = Data.Instance.Context.Countries.FirstOrDefault(d => d.Id == id);
Data.Instance.Context.DeleteObject(country);
Data.Instance.Context.SaveChanges();

country = Data.Instance.Context.Countries.FirstOrDefault(d=>d.Id == id);
Assert.IsNotNull(country); // Should not be able to retrieve the deleted entity by ID.

If that is not correct, can you post a minimal test case that shows this error - that would be an enormous help.

I've logged a bug over on the github account (https://github.com/BrightstarDB/BrightstarDB/issues/40), so if you want you can add comments directly there or just reply on this list.

Cheers

Kal


Oct 9, 2013 at 3:22 PM
It's still there - the delete does not actually delete anything, but it does seemingly add a blank item

For instance

public static int GetResultSize(object[] filters)
{
var pf = new ParsedFilters(filters);
try
{
return string.IsNullOrEmpty(pf.Filter1)
? Data.Instance.Context.Countries.Count()
: Data.Instance.Context.Countries.Count(d => d.Name.Contains(pf.Filter1));
}
catch (NullReferenceException)
{
return 0;
}
}

returns 13 (filter is empty)

but

public static IOrderedQueryable<ICountry> GetFilteredObjects(object[] filters)
{
var pf = new ParsedFilters(filters);
var result =
Data.Instance.Context.Countries
.Where(d => d.Name.Contains(pf.Filter1)
.OrderBy(d => d.SortName)
.Skip((pf.CurrentGroup - 1) * pf.GroupSize)
.Take(pf.GroupSize) as IOrderedQueryable<ICountry>;
return result;
}

returns the 9 expected results (including the deleted entity)


Kevin P. Hall
Vendor-Consultant
Research & Adv. Engineering
+1 309 578 4132
+1 412 327 0445



Oct 9, 2013 at 4:03 PM
when I run this code

protected override void DeleteItem()
{
saveButton.Enabled = false;
if (DataItem.CountryCatalogs.Count > 0)
{
foreach (var cat in DataItem.CountryCatalogs)
{
cat.CatalogCountries.Remove(DataItem);
}
}
Data.Instance.Context.DeleteObject(DataItem);
Data.Instance.Context.SaveChanges(); // exception thrown here
}

I get this exception

BrightstarDB.Client.BrightstarClientException was unhandled
HResult=-2146233088
Message=No Entity Found for Subject http://www.brightstardb.com/.well-known/model/wildcard
Source=BrightstarDB
StackTrace:
at BrightstarDB.Client.EmbeddedDataObjectStore.DoSaveChanges()
at BrightstarDB.Client.DataObjectStoreBase.SaveChanges()
at BrightstarDB.EntityFramework.BrightstarEntityContext.SaveChanges()
at StampCollector.EditScreens.CountryEdit.DeleteItem() in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\EditScreens\CountryEdit.cs:line 51
at StampCollector.EditScreens.EditBase.SaveButton_Click(Object sender, EventArgs e) in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\EditScreens\EditBase.cs:line 87
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at StampCollector.BrowseForms.CountryBrowse.OnMinusButtonClicked(EventArgs e) in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\BrowseForms\CountryBrowse.cs:line 98
at StampCollector.BrowseForms.BrowseBase.minusButton_Click(Object sender, EventArgs e) in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\BrowseForms\BrowseBase.cs:line 226
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at StampCollector.TempMain.countriesButton_Click(Object sender, EventArgs e) in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\TempMain.cs:line 20
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at StampCollector.Program.Main() in c:\Users\hallk2\Documents\Visual Studio 2012\Projects\StampCollector\StampCollector\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


Kevin P. Hall
Vendor-Consultant
Research & Adv. Engineering
+1 309 578 4132
+1 412 327 0445



Coordinator
Oct 9, 2013 at 4:14 PM
Hi,

This was reported and I thought it was fixed for 1.4 - see https://github.com/BrightstarDB/BrightstarDB/issues/32. Are you sure you are on version 1.4 ?

Cheers

Kal


Oct 9, 2013 at 4:16 PM
let me "clean" the project and rebuild. I downloaded the 1.4 version this morning, but the dll's might not have copied correctly


Kevin P. Hall
Vendor-Consultant
Research & Adv. Engineering
+1 309 578 4132
+1 412 327 0445



Oct 9, 2013 at 4:31 PM
I can't find the 1.4 embedded download


Kevin P. Hall
Vendor-Consultant
Research & Adv. Engineering
+1 309 578 4132
+1 412 327 0445



Coordinator
Oct 9, 2013 at 4:35 PM
You can either install it with NuGet (package name BrightstarDB) or get the download from http://brightstardb.codeplex.com/releases/view/112380