Hi,

Referring to an EntitySet<T> property where T is a base class using InheritanceSchema.SingleTable throws an exception. The instances of T can be loaded directly (i.e. with LINQ) without issue. Is this a fault, or am I not supposed to use EntitySet<T> properties with base types like this?

(The exception is an ArgumentException with the following message: "Item with key '[ColumnBelongingToDerivedType]' was not found", where the value between square brackets is the column involved).

Sorry if that wasn't clear - I can post sample code if it will help.

Cheers,

Matt.


Edit: Gah, I'm not supposed to post my response as an answer, but a comment won't accommodate my response, so I'll just have to edit it and jam it here. Not my favourite support tool =/


Hi Alex,

Thanks for the quick response (and for tidying up my post). Yes, I'm using PairTo with the EntitySet.

So, my case is something like this:

public class MyItem : Entity {
   ...
   [Association(PairTo="Item")]
   public EntitySet<MyBase> Items { get; private set; }
}

public abstract class MyBase : Entity {
   ...
   [Field]
   public MyItem Item { get; set; }
}

public class MyDerivedString : MyBase {
   ...
   [Field]
   public string MyStringField { get; set; }
}

public class MyDerivedDateTime : MyBase {
   ...
   [Field]
   public DateTime MyDateTimeField { get; set; }
}

If I do something like this (assume all the appropriate constructors are in place):

MyItem foo = new MyItem();
MyDerivedString s = new MyDerivedString("Hello");
MyDerivedDateTime d = new MyDerivedDateTime(DateTime.Now);

then everything writes through to the database correctly.

If I then retrieve the records like this:

List<MyBase> fields = Query
   .All<MyBase>()
   .ToList();

then the list is loaded correctly, and I can iterate through the correctly loaded types and their respective properties (i.e. there is no "slicing").

However, if I simply load the item and attempt to access it like this:

Item myItem = Query
   .All<MyItem>()
   .FirstOrDefault();

foreach(MyBase b in myItem.Items) {
...
}

then I get the error I originally posted.

From your previous post it sounds like this is expected behaviour. If so, why is loading automatically through use of an EntitySet different from issuing a LINQ query using the base type?

Cheers,

Matt.

asked Oct 11 '10 at 01:19

Matt%20Burnell's gravatar image

Matt Burnell
7113

edited Oct 11 '10 at 10:03

New info added in edit, as comment won't accommodate it.

(Oct 11 '10 at 20:28) Matt Burnell Matt%20Burnell's gravatar image

Most likely, there is a bug. It could be already fixed in today's nightly build - we've fixed one pairing-related issue there.

Could you publish the stack trace? We'll add the test for this case anyway, but stack trace should help us to identify the issue faster.

(Oct 13 '10 at 01:11) Alex Yakunin Alex%20Yakunin's gravatar image

I'd be happy to publish the stack trace, but the last build seems to have corrected the fault, so I guess you don't need it ;)

Thanks for fixing this so quickly.

(Oct 17 '10 at 20:14) Matt Burnell Matt%20Burnell's gravatar image

Good then ;)

(Oct 18 '10 at 00:03) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

Do you use [Association(PairTo = ...)] with this EntitySet? If so, does the field you're referencing there is declared in T? That's expected, otherwise you should pair to a descendant type.

If there is something else, probably, this is a bug.

answered Oct 11 '10 at 06:01

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA