Lo que sucede detrás de las cortinas cuando se incluyo una función en mi consulta compilada, como hago con DataConvert.ToThema() para convertir un objeto de tabla en mi costumbre objeto de negocio:incluyendo el código de "fuera de línea" en querys compilados
public static class Queries
{
public static Func<MyDataContext, string, Thema> GetThemaByTitle
{
get
{
var func = CompiledQuery.Compile(
(MyDataContext db, string title) =>
(from th in elan.tbl_Thema
where th.Titel == title
select DataConvert.ToThema(th)).Single()
);
return func;
}
}
}
public static class DataConvert
{
public static Thema ToThema(tbl_Thema tblThema)
{
Thema thema = new Thema();
thema.ID = tblThema.ThemaID;
thema.Titel = tblThema.Titel;
// and some other stuff
return thema;
}
}
y llamarlo como esto
Thema th = Queries.GetThemaByTitle.Invoke(db, "someTitle");
al parecer, la función no se traduce en SQL o algo (¿cómo podría), sino que además no se sostiene cuando me puse un punto de interrupción allí en VS2010.
Funciona sin problemas, pero no entiendo cómo ni por qué. ¿Qué pasa exactamente allí?
LINQ to EF no puede hacer esto. –