This question is locked. New answers and comments are not allowed.
Hello Telerik team.
I have a list of objects from DB:
Initially this list - is a list of some Standard objects.
During work user can change all of them. BUT if he want to save his changes - he can save only "Save as..."
So, he can't reWrite Standard objects. Only create new (his own object) and then Save (Commit).
So, before Commit() I create a copy of Standard object
and now I should Add userEntity to a scope and Commit();
but How I can NOT COMMIT Standard object???
Because now it is Changed too. Because user changed it earlier. Before Click <Save as...>
I know about
But I need Use Changed Standard object during this session. But without save to DB.
And when user load all Standard objects from DB next time - he must look Standard objects - not changed.
Is it possible to realize?
Thanks!
I have a list of objects from DB:
IList<Entity> myList = from p
in
scope.Extent<Entity>() select p;
During work user can change all of them. BUT if he want to save his changes - he can save only "Save as..."
So, he can't reWrite Standard objects. Only create new (his own object) and then Save (Commit).
So, before Commit() I create a copy of Standard object
var userEntity =
new
Entity();
StandardEntity.CopyTo(userEntity);
but How I can NOT COMMIT Standard object???
Because now it is Changed too. Because user changed it earlier. Before Click <Save as...>
I know about
transaction.Rollback();
And when user load all Standard objects from DB next time - he must look Standard objects - not changed.
Is it possible to realize?
Thanks!
10 Answers, 1 is accepted
0
IT-Als
Top achievements
Rank 1
answered on 16 Jun 2011, 09:34 AM
Hi Andrey,
You could try using the Refresh method on the Standard object before commit. It will "clean" the instance with the information from the database.
Regards
Henrik
You could try using the Refresh method on the Standard object before commit. It will "clean" the instance with the information from the database.
Regards
Henrik
0
Hi Andrey,
Petar
the Telerik team
What Henrik suggested should do the trick for you. Basically when you commit our object tracking fires in and generates sql queries for all the objects that are market as "dirty" (modified in the given transaction). What the Refresh method does is to reset the original values of the object and remove the "dirty" status from it.
All the best,Petar
the Telerik team
0
IT-Als
Top achievements
Rank 1
answered on 24 Jun 2011, 09:13 AM
Hi Andrey,
If the answer above solved your issues, please mark it as answered so that other forum visitors will be able to find an answer to their question quickly.
Best regards
Henrik
If the answer above solved your issues, please mark it as answered so that other forum visitors will be able to find an answer to their question quickly.
Best regards
Henrik
0
LordRevan007
Top achievements
Rank 1
answered on 16 Aug 2011, 09:47 AM
I tried the suggested solution but with no effect. I use a postgresql database.
Any hints on how to do this?
Thanks in advance
Any hints on how to do this?
Thanks in advance
0
IT-Als
Top achievements
Rank 1
answered on 16 Aug 2011, 09:51 AM
Hi,
What doesn't work?
Refresh should clear the dirty flags and thus omit the objects from being committed. Show us some code, please..
/Henrik
What doesn't work?
Refresh should clear the dirty flags and thus omit the objects from being committed. Show us some code, please..
/Henrik
0
LordRevan007
Top achievements
Rank 1
answered on 16 Aug 2011, 10:27 AM
It doesn't clear the dirty flag. I have two tables with an 1 to many relationship in them.
For example:
Product(idProduct, name, idProductType)
ProductType(idProductType,name).
If I want to add a product with a given product type from the db it will add a new product type also.
I tried with ctx.refresh in all sort of combinations but still with no result.
My code looks like the following snippet.
Thanks in advance
For example:
Product(idProduct, name, idProductType)
ProductType(idProductType,name).
If I want to add a product with a given product type from the db it will add a new product type also.
I tried with ctx.refresh in all sort of combinations but still with no result.
My code looks like the following snippet.
var t=
new
Product();
t.name=
"test"
;
var tp=managerProductType.GetProductTypeById(1);
t.ProductType=tp;
ctx.Add(t);
ctx.Refresh(RefreshMode.OverwriteChangesFromStore,t.ProductType)
ctx.SaveChanges();
Thanks in advance
0
IT-Als
Top achievements
Rank 1
answered on 16 Aug 2011, 10:37 AM
Hi,
How is the 1:m relationship mapped... with an inverse field (foreign key column in the table representing the ProductType entity)? Or a join table (like a product_producttype table)?
When you go and get the ProductType entity from the database and NOT add it to the context with the Add method it should work.
However, if your 1:m is mapped with an inverse field only 1 product can reference the same product type... I guess what you want to achieve is the product to have exactly 1 (of some predefined( already existing in database) product type, right?
if so this is a either a 1:m with a join table or a m:n.... Eventually see the knowledge base article on mapping 1:1 relationsships.
Regards
Henrik
How is the 1:m relationship mapped... with an inverse field (foreign key column in the table representing the ProductType entity)? Or a join table (like a product_producttype table)?
When you go and get the ProductType entity from the database and NOT add it to the context with the Add method it should work.
However, if your 1:m is mapped with an inverse field only 1 product can reference the same product type... I guess what you want to achieve is the product to have exactly 1 (of some predefined( already existing in database) product type, right?
if so this is a either a 1:m with a join table or a m:n.... Eventually see the knowledge base article on mapping 1:1 relationsships.
Regards
Henrik
0
LordRevan007
Top achievements
Rank 1
answered on 16 Aug 2011, 10:57 AM
The relationship is mapped with an inverse field. In my case the Fk key from Products idProductType references to idProductType from my ProductType table. If I send only the idProductType works, but if I send the object ProductType that is associated with Product it add that ProductType also. What I want is not to add that ProductType.
0
IT-Als
Top achievements
Rank 1
answered on 16 Aug 2011, 11:06 AM
Hi,
Try to map it as a 1:m with a join table instead.
The "problem" with the inverse field is that OA thinks that the "owner" of the list (the 1 side) must be saved, too, if you change (add an item) the list (the many side).
Regards
Henrik
Try to map it as a 1:m with a join table instead.
The "problem" with the inverse field is that OA thinks that the "owner" of the list (the 1 side) must be saved, too, if you change (add an item) the list (the many side).
Regards
Henrik
0
LordRevan007
Top achievements
Rank 1
answered on 16 Aug 2011, 11:07 AM
Thanks I'll give it a shot.
LordRevan007
LordRevan007