This is a migrated thread and some comments may be shown as answers.

[Solved] I don't want save foreigh key - Object1 from saved Object2

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrey
Top achievements
Rank 1
Andrey asked on 14 Sep 2010, 02:58 PM

My soft supports several Operators.

Each Operator can configure Some Entity as he wants.

Operator can change name, color and so on (in SomeEntity).

I load List<SomeEntity> from Db. And then current Operator can change what he wants.

Then I should get all changes from each SomeEntity - and save to DB in [Operator]-table.

But I don't want save a SomeEntity class in DB.

SomeEntity contains only default values. And when something was changed - these changes saved in Operator-table. But not in SomeEntity.

How I should organize saving to DB such Operator configurations?

I have such classes:

01.[Persistent]
02.public class Operator
03.{
04.  public string OperatorName {get; set;}
05.  public SomeEntity Entity {get; set;}
06.  public string EntityName {get; set;}
07.  public string EntityDescription {get; set;}
08.  public Color EntityColor {get; set;}
09.  // .....
10.    
11.  
12.}
13.  
14.[Persistent]
15.public class SomeEntity
16.{
17.  public string Name {get; set;}
18.  public string Description {get; set;}
19.  public Color Color {get; set;}
20.  // .....
21.  
22.}

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 17 Sep 2010, 01:44 PM
Hello Andrey,

 Let me see if I understand correctly, you store default values in the SomeEntity table and you want to modify the Operators table. Your current setup looks okay, but I do not see a reason for the Operator to have a reference to SomeEntity. When you have such reference there is no way to avoid having a foreign key in the database, except for marking the field as transient. In that case you will have to add your own logic for loading this field though. Also you shouldn't modify the SomeEntity objects if you do not want them persisted to the database. I would rather get a new Operator set the initial values of its properties based on a SomeEntity object.

Please contact us back if you face further difficulties. I hope this helps.

Best wishes,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Andrey
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or