With not nullable link field on inherited enities
model:
[Serializable]
[HierarchyRoot]
public abstract class MyEntity : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field(Length = 100)]
public string Text { get; set; }
}
[HierarchyRoot]
public class SomeEntity : Entity
{
[Field, Key]
public int Id { get; private set; }
[Field(Length = 100)]
public string Text { get; set; }
}
public class MyEntityWithLink : MyEntity
{
[Field(Nullable = false)]
public SomeEntity link { get; set; }
}
public class MyEntityWithText : MyEntity
{
[Field]
public string someData { get; set; }
example data:
var se1 = new SomeEntity { Text = "se1" };
var se2 = new SomeEntity { Text = "se2" };
var mie1 = new MyEntityWithLink { link = se1, Text = "MyEntityWithLink" };
var mie2 = new MyEntityWithLink { link = se2, Text = "MyEntityWithLink" };
var mihe2 = new MyEntityWithText() { someData = "ololo", Text = "MyEntityWithText" };
query with wrong behavior:
// if MyEntityWithLink.SomeEntity - decorated with [Field(Nullable = false)] - there are no MyEntityWithText data
// if MyEntityWithLink.SomeEntity - decorated with [Field(Nullable = true)] - ok
var items = Query.All<MyEntity>().OrderBy(a => a.Id)
.Select(q =>
(q as MyEntityWithLink != null)
? new { d = (q as MyEntityWithLink).link.Text }
: new { d = (q as MyEntityWithText).someData });
asked
Jan 14 '11 at 03:46
pil0t
207●57●57●63