How to get object from class name and ID?
CapableObjects Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



How to get object from class name and ID? Expand / Collapse
Author
Message
Posted 2010-04-02 00:53:58
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2011-12-15 02:08:37
Posts: 35, Visits: 260
Like title,If I know the class name and id (not ExternalId,is really id in database);How can get this object?
Another question,if I have the ExternalId,how to get the class name and id. (not to load object,then get the object type name)
thank you !
Post #5104
Posted 2010-04-13 09:39:13
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230, Visits: 1 382
To get the object if you have the primary key and classname:

     object key = 1234;
IObject obj = EcoSpace.CacheContent.GetObject(key, "MyClass");

The purpose of the ICacheContentService is to be able to stuff things into the ecospace objectcache as if they came from the database. If you have some scenario where the performance in ECO is not sufficient and a custom crafted SQL can load alot of data very quickly, you can load it directly from the db and stuff it into the cache. A sideeffect is that it allows you to convert a primary key to the corresponding object (without loading it from the db).

When you transform from an ExternalId to an object:

      string id = "123!123123";
IObject obj2 = EcoSpace.ExternalIds.ObjectForId(id);

the object will be automaticlly fetched. The ExternalId normally consists of index of the type in the runtime model and the primary key.


      string[] parts = id.Split('!');
string classname = EcoSpace.TypeSystem.AllClasses[int.Parse(parts[0])].Name;
int key2 = int.Parse(parts[1]);


but this only work for the simple case where the object is already persisted in the database and the key is an int32 and you are using the default externalid mechanism. The only safe way to transform an externalid back to an object is to use the same ExternalId service implementation that generated it.


/Jonas Hogstrom [CapableObjects]
Post #5140
Posted 2010-08-26 18:59:08
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 2010-08-27 16:54:01
Posts: 1, Visits: 9
Hi,

I Have the same problem in ECO3 and BDS2006
I Have a SQLQuery which give me

ECO_TYPE, ECO_ID, Attr1, Attr2
43, 2540, C001, Customer1
43, 2780, C002, Customer2

In my app, if I use GetIDForObject, the result is 65:2540 and 65:2780

How can I load these objects in the ecospace (I Know the good classname)?


I have download your app sample (customfetch), but in my version, ICacheContentService doesn't exist.

Thanks



Post #5493
Posted 2010-08-27 09:40:25
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2012-02-01 10:36:37
Posts: 101, Visits: 751
In ECO3 there is no ICacheContentService. If upgrading Eco is not an option, try EcoSqlCondition http://ecosqlcondition.codeplex.com/releases/view/29054
The first version works with Eco4, but with minor changes it should run with Eco3.


/Pawel
Post #5496
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: HansKarlsen, Jonas Hogstrom, PeterMorris

Permissions Expand / Collapse

All times are GMT +1:00, Time now is 4:30

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0,156. 9 queries. Compression Disabled.