New Posts New Posts RSS Feed: Default Values
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Default Values

 Post Reply Post Reply
Author
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Topic: Default Values
    Posted: 14-May-2010 at 10:32pm
There are a lot of scenarios here so let me try to cover them one by one.
 
In general, you specify the default value for the property in the Entity Framework designer, and when the object is created, DevForce will set those properties to their default values.  This doesn't solve the problem that the Entity Framework does not get the default from SQL Server, but within DevForce, there should not be a problem where validation fails before the default value is set.
 
Now for the specific cases:
 
If want the server to record the Owner for the record (instead of doing this in the client) you can do this in the EntityServerSaveInterceptor.  Here, by overriding ExecuteSave(), you can modify the Order's Owner to the current user just before the save.
 
For primary key fields, DevForce has an IIdGenerator interface that allows the client to create new records with temporary ids and the server will assign them the permanent primary keys just before save.  DevForce will then will fixup the object graph to correct all the foreign key references to the permanent primary key value.
 
I believe you may be working with our professional services, so we can go over these patterns in more detail when you're ready to start.
 
Back to Top
iosub View Drop Down
Newbie
Newbie


Joined: 20-Apr-2010
Location: Spain
Posts: 24
Post Options Post Options   Quote iosub Quote  Post ReplyReply Direct Link To This Post Posted: 13-May-2010 at 5:13am
Hi
 

How do you support default values for fields? Do you define on the EF model or partial class?

For example:
I want that each time I create a new record on "orders" the default value for "Owner" will be the user that has login on the application. So my silverlight app does not have to have the code for the default value and is only defined on the server. So every client that will conect to the server will have the same default value
 
WCF for RIA does not hadled this correctly, it use the Oncreate method that you have to share with the client. This has problems because if I change the Server code, I have to update all my clients.
 
Another problem with EF is that does not get this information from the default value defined on the SQL Server, it does not work if you define the default value on the EF model either, so when you create a new value con the SL client and you have a validation, if the value is emptly the validation fails.. So the only solution is to use "oncreate".
 
I have also try with <DEFAULT> atribute on the metadata but it does not work.. because the validation on SL goes before the <Default>..
 
There is also another problem with Default values on WCF Ria. If the field is a KEY it has the attribute <Requiered> so the default value does not work at all. I have always need to do the Oncreate. Here is a problem, because if I have a KEY Field that has to be calculated (example OrderNumber that is the last Order of the customer+1) I want to calculate this value on the save moment.. If I do it before and the user cancels the order I have emptly orders Numers.. I can't do it on the SQLserver with a trigger because the Validation on the SL client
 
How do you support this on DF??
 
 
Thanks!
 
 
The good idea

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down