GitHub    Download    Forum
Overview
Tutorial
Database setup
Preparing the project
Establish the connection
Shut down the connection
DTDL types
Creating the schema
DADL classes
Entry point object
Write and read attributes
Write and read lists
Extending the schema
Modified entry point object
Write and read objects
Write and read object lists
C++ API
C# API
WinRT API
DTDL
DADL
Setup
C++
C#

Modified entry point object

We already have an entry point object. The existing one has one class (Supplies). But now, we want to extend it and have an entry point object with two classes (Supplies and Inventory). To do this, we add a new class to the existing object and update (replace) the named object link.
WSupplies* pSupplies = NULL;
WInventory* pInventory = NULL;

DataFS::stcObjectLink* pInventoryLink;
if(S_OK == pDomain->QueryNamedLink(&guidEntryPoint, 1, &pInventoryLink, NULL))
{
	if(WInventory::IsOfType(pInventoryLink))
	{
		WInventory::Open(&pInventory, pDomain, *pInventoryLink);
		pInventory->Load();

		DataFSAccess::MemFree(pInventoryLink);

		if(FAILED(pDomain->Execute(Transaction::Load, NULL)))
		{
			wprintf(L"Execute failed...\n");
			uninit(pConnection, pDomain, ulStorageId);
			return -1;
		}

		pSupplies = WSupplies::CastTo(pInventory->GetObject());
	}
	else if(WSupplies::IsOfType(pInventoryLink))
	{
		DataFSAccess::MemFree(pInventoryLink);

		wprintf(L"Object is not of type WInventory but of type WSupplies\n");
	}
	else
	{
		DataFSAccess::MemFree(pInventoryLink);

		wprintf(L"Object is not of type WInventory\n");
	}
}
else
{
	WInventory::Create(&pInventory, pDomain, &DataFS::OBJECTID_NULL);

	pDomain->InsertNamedLink(&pInventory->BuildLink(true), &guidEntryPoint, L"extended entry point");

	pSupplies = WSupplies::CastTo(pInventory->GetObject());

	// Store
	pInventory->Store();

	// Execute
	HRESULT hRes;
	if(FAILED(hRes = pDomain->Execute(Transaction::Store, NULL)))
	{
		wprintf(L"Domain failed to execute the transaction (0x%x)\n", hRes);

		pSupplies->Release();
		pSupplies = NULL;
	}
}
WSupplies pSupplies = null;
WInventory pInventory = null;

DataFS.Array<DataFS.stcObjectLink> apInventoryLink = new DataFS.Array<DataFS.stcObjectLink>();
if (0 == pDomain.QueryNamedLink(aguidEntryPoint, apInventoryLink, null))
{
	if (WInventory.IsOfType(apInventoryLink.pData[0]))
	{
		WInventory.Open(out pInventory, pDomain, apInventoryLink.pData[0].oiObjectId, 0, Transaction.Load);
		pInventory.Load(_WInventory.ALL_ATTRIBUTES, Transaction.Load);

		if (0 > pDomain.Execute(Transaction.Load, null))
		{
			Console.WriteLine("Execute failed...");
			uninit(pDomain, ulStorageId);
			return;
		}

		pSupplies = WSupplies.CastTo(pInventory.GetObject());
	}
	else if (WSupplies.IsOfType(apInventoryLink.pData[0]))
	{
		Console.WriteLine("Object is not of type WInventory but of type WSupplies");
	}
	else
	{
		Console.WriteLine("Object is not of type WInventory");
	}
}
else
{
	WInventory.Create(out pInventory, pDomain, DataFS.ObjectId.OBJECTID_NULL);

	pDomain.InsertNamedLink(pInventory.BuildLink(true), guidEntryPoint, "extended entry point", Transaction.Store);

	pSupplies = WSupplies.CastTo(pInventory.GetObject());

	// Store
	pInventory.Store(Transaction.Store);

	// Execute
	int hRes;
	if (0 > (hRes = pDomain.Execute(Transaction.Store, null)))
	{
		Console.WriteLine("Domain failed to execute the transaction (0x{0:x})", hRes);

		pInventory = null;
		pSupplies = null;
	}
}
Now our object has two classes. Our new code can use both classes, but the old code still works. No changes are required here.
© 2025 Mobiland AG