The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
How to use pre-generated keys with entity framework.
Posted: 03 Dec 12 1:37 PM
|
fiogf49gjkf0d Is it possible to use pre-generated keys with the entity framework.
1. Retrive a generated key.
2. Create an entity(Contact for example), set the key value to the generated key, then save.
I need the OnCreate and OnBeforeInsert events to fire which is why Im not just inserting the record into the datbase with the generated key value. |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 7:07 AM
|
fiogf49gjkf0d Hi Matthew,
What method are you using to import the new record? If you are calling to the framework your associated entity events should fire. IF you are trying to push them in via SQL or such, they will not.
Carla |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 8:14 AM
|
fiogf49gjkf0d Im using a business rule.
The problem im having is being able to create a new entity with the framework and setting its Id property. Its read only. Was looking for a work around if one existed. |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 8:33 AM
|
fiogf49gjkf0d OK, let me make sure I understand what you are saying. You will be *inside* of SalesLogix while creating a new record, but you don't want to use the UID generation provided with SalesLogix, nor the Insert method? Is that correct?
Are you using pre-generated SLX numbers? If you are trying to provide your own UID; I would strongly recommend against it. There are a number of underpinnings in the product that could get completely out of whack. |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 8:44 AM
|
fiogf49gjkf0d When you said "Insert method" in your last post, do you mean a sql insert or a method in the framework named "Insert"?
If sql insert, then thats not an option since events want fire.
Short story:
Writing a disconnected client that primarly uses sdata. We generate a sage formatted key with its on site code. However, sdata does not support sending a key during creation. Next though was to use a business rule to do the creation.
|
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 9:03 AM
|
fiogf49gjkf0d OK, now that we have cleared up what type of insert you are trying to accomplish, I am wondering why you aren't using the disconnected client to do the work for you. It will handle all of that (site code included) and fire the required rules when it sends data up. I think I am missing something else here as recreating the record and sending it via sdata is a redundant process.
Can you please let us know why you are doing this so we can help figure out the best method for you to use? |
|
|
| |
|
Re: How to use pre-generated keys with entity framework.
Posted: 04 Dec 12 9:58 AM
|
fiogf49gjkf0d The SalesLogix application is not installed on the device. Its sort of mimicing a disconnected client. The part I'm working on is the syncronization. This is also on a very small scale. Only a couple of entities.
Thanks for the replys so far. |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 05 Dec 12 6:11 AM
|
fiogf49gjkf0d Originally posted by Matthew Arnold
Is it possible to use pre-generated keys with the entity framework.
1. Retrive a generated key.
2. Create an entity(Contact for example), set the key value to the generated key, then save.
I need the OnCreate and OnBeforeInsert events to fire which is why Im not just inserting the record into the datbase with the generated key value.
|
|
Try this if it helps
Dim PregenKey
PregenKey = Application.BasicFunctions.GetIDFor("C_My_Table_Name")
Comment: "C_My_Table_Name" being the name of the table
|
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 06 Dec 12 11:02 AM
|
fiogf49gjkf0d Ok, and the reason you don't want to use sData insert is because you wan tyour pregenerated keys to have a particular sitecode in the key, is that correct or is there another reason you want your pregenerated keys? |
|
|
|
Re: How to use pre-generated keys with entity framework.
Posted: 06 Dec 12 12:21 PM
|
fiogf49gjkf0d Hey Matthew,
Sadly, neither the entity framework or SData allow you to specify the ID for the record you are creating. This can be a huge pain at times. For me this is usually because I want to do things with the record ID before the actual record gets created (like create a pretty key). Instead I usually rearrage my workflow so I create the record, then get the key and do whatever I needed to do with it. Sadly, though, if you're wanting to specify some custom ID value to use, this won't work on an update either. Only way to do it is using a business rule that bypasses the entiy framework and updates the SQL table directly with the custom ID value (easy enough to do using the DataService).
Ryan |
|
|
| |
|