EXCEPCION : Query was compiled for a different mapping source than the one associated with the specified DataContext.

Para dar las gracias debes entrar o registrarte en el foro

Nuevo miembro
Nuevo miembro
Mensajes: 2 Agradecido: 0
10 Dic 2011, 20:59# 1

Hola estoy trabajando con SQL Server CE y tengo un problema que realmente me esta constando resolver.

El problema es que estoy trabajando con consulta compiladas , ejemplo :

Func GetLoan = CompiledQuery.Compile(
( AppDbContext Appcontext, String person ) =>
(from l in Appcontext.Loans
where l.person.Equals(person)
select l).FirstOrDefault());

Y todo va bien cuando estoy en esta pagina que es un panorama, todo se carga correctamente, pero tengo un boton editar para editar la informacion de un registro, entonces al navegar al pivot item de editar y volver me da esta excepcion:

EXCEPTION: Query was compiled for a different mapping source than the one associated with the specified DataContext.

Al llamar a la consulta compilada que he puesto arriba.

codigo:

using(AppDbContext context = new AppDbContext("Data Source='isostore:/AccountAssistantDb.sdf'"))
{


ListBox1.ItemsSource = (from rc in context.ReferencesCharges
where rc.chargeId.Equals(selectedItemDataChargeDestination.chargeId)
orderby rc.date descending
select rc).ToList();

Loan auxloan = GetLoan(context, selectedItemDataChargeDestination.person); //Aqui la excepcion!

if(auxloan != null)
{

ListBox2.ItemsSource = (from rl in context.ReferencesLoans
where rl.loanId.Equals(auxloan.loanId)
orderby rl.date descending
select rl).ToList();
}
}

Se supone que cambia el data context pero no se que hacer porque yo cada vez que quiero ejecutar la consulta tengo que
usar un datacontext con la linea de codigo

using(AppDbContext context = new AppDbContext("Data Source='isostore:/AccountAssistantDb.sdf'"))


TODAVIA NO ESTOY EDITANDO SIMPLEMENTE HE HECHO LA NAVEGACION Y YA ME DA FALLO, SUPONGO QUE CUANDO EDITE LA CONSULTA TENDRA QUE SER CON UN NUEVO DATA CONTEXT POR NARICES YA QUE TENGO UN CAMPO QUE HA CAMBIADO.

Muchas Gracias,

No se si me he explicado bien pero si necesitais cualquier tipo de informacion mas para ayudarme me lo decis.

Ya he estado investigando por internet y dicen porque ocurre pero no como resolverlo, practicamente acabas aqui siempre:

http://connect.microsoft.com/VisualStud ... -compiling

Gracias de nuevo

Gracias  
Etiquetado en:
Nuevo miembro
Nuevo miembro
Mensajes: 2 Agradecido: 0
10 Dic 2011, 21:09# 2

Asi va perfectamente, asi que el problema es de la consulta compilada. Me estan dando muchos problemas esta consultas compiladas, tambien con los cast al hacer un .toList() son una lata.

using(AppDbContext context = new AppDbContext("Data Source='isostore:/AccountAssistantDb.sdf'"))
{




ListBox1.ItemsSource = (from rc in context.ReferencesCharges
where rc.chargeId.Equals(selectedItemDataChargeDestination.chargeId)
orderby rc.date descending
select rc).ToList();

Loan auxloan = (from l in context.Loans
where l.person.Equals(selectedItemDataChargeDestination.chargeId)
select l).FirstOrDefault();

//Loan auxloan = GetLoan(context, selectedItemDataChargeDestination.person); //comente esto para hacer lo mismo como se ve justo encima

if(auxloan != null)
{

ListBox2.ItemsSource = (from rl in context.ReferencesLoans
where rl.loanId.Equals(auxloan.loanId)
orderby rl.date descending
select rl).ToList();
}
}

Gracias  