Hello,
More fun with QuerySpec...
In my LLBLGen project I am using inheritance (Target-per-Entity-Hierarchy I think), and some custom templates that create POCO-like objects I project records on to. My templates actually carry over the inheritance too, but I wasn't really able to leverage it using LINQ, but it looks like I can using QuerySpec + WithProjector?
I am wondering how this could best be achieved, rather than the less desirable approach I just brainstormed below.
Here's some example code:
Base
public partial class SourceAdvisoryMetaData : IMetaData
{
[Key]
public virtual System.Int32 SourceAdvisoryId { get; set; }
public virtual System.String Description { get; set; }
public virtual System.String Title { get; set; }
// Mapped fields on related field.
}
Subtype
public partial class SourceAdvisoryFooMetaData : SourceAdvisoryMetaData, IMetaData
{
public virtual System.DateTime AdvisoryDate { get; set; }
public virtual System.String Criticality { get; set; }
...
}
So with QuerySpec, I am thinking since I have to use a DynamicQuery, I select all my fields first, then use WithProjector, and based upon some value existing in the selection criteria I would be able to return the type of object it is, either a base (SourceAdvisoryMetaData) or a child (SourceAdvisoryFooMetaData).
But that doesn't seem ideal.
Query
var q = qf.SourceAdvisory
.Select(() => new
{
// Base
SourceAdvisoryId = SourceAdvisoryFields.SourceAdvisoryId.ToValue<int>(),
Title = SourceAdvisoryFields.Title.ToValue<string>(),
Description = SourceAdvisoryFields.Description.ToValue<string>(),
// ...
// Child
AdvisoryDate = SourceAdvisoryFooFields.AdvisoryDate.ToValue<DateTime?>(),
Criticality = SourceAdvisoryFooFields.Criticality .ToValue<string>(),
}
)
.WithProjector(t =>
{
// It's a subtype
if (t[12] != null)
{
return new SourceAdvisoryFooMetaData { };
}
// It's a basetype
return new SourceAdvisoryMetaData { };
}
)
;
How might the actual type be accessed in a DynamicQuery so I can create the correct projected POCO type (probably a cake-and-eat-it-too kind of question)?
Thanks!