Purely from what you've given,I think both of them are right in syntax。But if your answer is "this.EntityState != EntityState.Added"——this means that your ObjectStateManager doesn't have this kind of instance,it will avoid being duplicatedly added。 So if
possible,What's the real question?
You write the following code segment. (Line numbers are included for reference only.) 01public partial class SalesOrderDetail : EntityObject 02{ 03partial void OnOrderQtyChanging(short value) 04{ 05 06{ 07... 08} 09} 10} You need to find out whether the object has a valid ObjectStateEntry instance. Which code segment should you insert at line 05? A. If (this.entitystate != entitystate.Detached) B. If (this.entitystate != entitystate.Unchanged) C. If (this.entitystate != entitystate.Modified) D. If (this.entitystate != entitystate.Added)
The correct answer is D. but i would like a explain.
I totally agree with you. For me is A. But if you google this question you will find D as answer. So if definitely the correct is D, i would like a explain cause i do not understand how it can be D.
I totally agree with you. For me is A. But if you google this question you will find D as answer. So if definitely the correct is D, i would like a explain cause i do not understand how it can be D.
OK,I'll submit your question to another expert in this and we'll reply to you when we are free……We'll talk and get the result for you……
</div> <div>"The object exists but is not being tracked. An entity is in this state immediately after it has been created and before it is added to the object context. An entity is also in this state after it has been removed from the context by calling
the Detach method or if it is loaded by using a NoTracking MergeOption.
There is no ObjectStateEntry instance associated with objects in the Detached state."</div> <div> </div> <div>My conclusion about the bolded phrase: The detached mode of the entity does not have a valid ObjectStateEntry instance in ObjectStateManager class.</div> <div>What the question ask: "you need to find out whether the object has a valid ObjectStateEntry
instance."
My conclusion: "A" would be the correct cause Detached is the only mode that there isn't a ObjectStateEntry instance. Unless he consider "valid" as having a original value in ObjectStateEntry.</div> <div></div> <div>One thing is certain for me about this question:
The question was not well elaborated. (Unless i'm totally incorrect)</div>
Rui_Brazil
Member
22 Points
7 Posts
Doubt with EntityStateEntry
Jan 10, 2012 06:04 PM|LINK
Hi, i'm praparing for 70-516 exam, but i have a some doubts :/ . So let's start... I need to verify with a EntityStateEntry is valid for one object.
I have:
public class ExampleClass()
{
public void exampleVerifyisValid()
{
if(this.EntityState != EntityState.Detached)
or
if(this.EntityState != EntityState.Added)
//...code
}
}
Which way is correct ? For me is Detached, but people say that the correct is Added. But i did not understand why... Can anyone explain me ?!
Rui_Brazil
Member
22 Points
7 Posts
Re: Doubt with EntityStateEntry
Jan 11, 2012 05:16 PM|LINK
No one knows about EntityStateEntry ?! :/
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Doubt with EntityStateEntry
Jan 12, 2012 12:53 AM|LINK
Hello:)
Purely from what you've given,I think both of them are right in syntax。But if your answer is "this.EntityState != EntityState.Added"——this means that your ObjectStateManager doesn't have this kind of instance,it will avoid being duplicatedly added。 So if possible,What's the real question?
Best reguards!
Rui_Brazil
Member
22 Points
7 Posts
Re: Doubt with EntityStateEntry
Jan 12, 2012 03:56 AM|LINK
You write the following code segment. (Line numbers are included for reference only.)
01public partial class SalesOrderDetail : EntityObject
02{
03partial void OnOrderQtyChanging(short value)
04{
05
06{
07...
08}
09}
10}
You need to find out whether the object has a valid ObjectStateEntry instance.
Which code segment should you insert at line 05?
A. If (this.entitystate != entitystate.Detached)
B. If (this.entitystate != entitystate.Unchanged)
C. If (this.entitystate != entitystate.Modified)
D. If (this.entitystate != entitystate.Added)
The correct answer is D. but i would like a explain.
Thanks.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Doubt with EntityStateEntry
Jan 12, 2012 04:11 AM|LINK
"Has a valid ObjectStateEntry instance" ——In my mind,I think perhaps it means whether the ObjectStateEntry exists or not,I prefer to choose A。
D means to check whether the instance is added to the query of ObjectStateManager。
Best reguards!
Rui_Brazil
Member
22 Points
7 Posts
Re: Doubt with EntityStateEntry
Jan 12, 2012 02:40 PM|LINK
I totally agree with you. For me is A. But if you google this question you will find D as answer. So if definitely the correct is D, i would like a explain cause i do not understand how it can be D.
Thanks a lot
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Doubt with EntityStateEntry
Jan 13, 2012 12:04 AM|LINK
OK,I'll submit your question to another expert in this and we'll reply to you when we are free……We'll talk and get the result for you……
Best regaurds...
binvij
Member
78 Points
19 Posts
Re: Doubt with EntityStateEntry
Jan 19, 2012 08:00 AM|LINK
If the orderQty has a value and is being updated then the correct state is
EntityState.Modified
However, if the orderQty has been just been initialized for a new object instance of SalesOrderDetail, then the correct state is
EntityState.Added
Hope this helps
Thanks
Bindesh-MSFT
SQL Developer Support Forums Escalation
Rui_Brazil
Member
22 Points
7 Posts
Re: Doubt with EntityStateEntry
Jan 21, 2012 11:44 PM|LINK
There is no ObjectStateEntry instance associated with objects in the Detached state."</div> <div>
</div> <div>My conclusion about the bolded phrase: The detached mode of the entity does not have a valid ObjectStateEntry instance in ObjectStateManager class.</div> <div>What the question ask: "you need to find out whether the object has a valid ObjectStateEntry instance."
My conclusion: "A" would be the correct cause Detached is the only mode that there isn't a ObjectStateEntry instance. Unless he consider "valid" as having a original value in ObjectStateEntry.</div> <div></div> <div>One thing is certain for me about this question: The question was not well elaborated. (Unless i'm totally incorrect)</div>
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Doubt with EntityStateEntry
Feb 11, 2012 04:28 AM|LINK
Hi,
I was found EF 4.1 up is flexible however you can convert DbContext back to ObjectContext by using IObjectContext.
http://blogs.msdn.com/b/adonet/archive/2011/01/30/using-dbcontext-in-ef-feature-ctp5-part-5-working-with-property-values.aspx
Weera