This question is locked. New answers and comments are not allowed.
HI,
I Got an error trying to join on multiple entities.
I Have 3 tables/Classes
EstoqueItens ( My Itens)
EstoqueItensTipos ( My Iten's types)
EstoqueItensStatus ( My Iten's Status)
EstoqueQtdItem ( Where I record the actual quantity of my itens )
I Just want to retrieve something like i Got with the SQL query:
I got success with LINQPad trying this
But when I Tried the same with OpenAccessORM
I got this error
I can put my database model here if needed
Thanks
I Got an error trying to join on multiple entities.
I Have 3 tables/Classes
EstoqueItens ( My Itens)
EstoqueItensTipos ( My Iten's types)
EstoqueItensStatus ( My Iten's Status)
EstoqueQtdItem ( Where I record the actual quantity of my itens )
I Just want to retrieve something like i Got with the SQL query:
| select |
| Item.Cod as Cod, |
| Item.Nome as Nome, |
| Item.Info as Info, |
| Item.QtdMin as QtdeMin, |
| Item.MesesValidade as Validade, |
| Item.Cat as Categoria, |
| Item.Status as StatusId, |
| S.Status as Status, |
| Item.Tipo as idTipo, |
| T.Tipo as Tipo, |
| Q.Qtd as Atual |
| from |
| EstoqueItens Item |
| inner join EstoqueItensTipo T on Item.Tipo = T.idTipo |
| inner join EstoqueItensStatus S on Item.Status = S.Id |
| inner join EstoqueQtdItem Q on Item.Cod = Q.Cod |
I got success with LINQPad trying this
| var query =from Item in EstoqueItens |
| join T in EstoqueItensTipos on Item.Tipo equals T.IdTipo |
| join S in EstoqueItensStatuses on Item.Status equals S.Id |
| join Qtde in EstoqueQtdItems on Item.Cod equals Qtde.Cod |
| where Item.Empresa == 1 |
| orderby Item.Cat descending,Item.Cod descending |
| select new { |
| Cod = Item.Cod, |
| Nome = Item.Nome, |
| Info = Item.Info, |
| QtdeMin = Item.QtdMin, |
| Validade = Item.MesesValidade, |
| Empresa = Item.Empresa, |
| Categoria = Item.Cat, |
| StatusId = Item.Status, |
| Status = S.Status, |
| TipoId = Item.Tipo, |
| Tipo = T.Tipo, |
| Atual = Qtde.Qtd |
| } ; |
| query.Dump ("Join query"); |
But when I Tried the same with OpenAccessORM
| IObjectScope scope = ObjectScopeProvider1.ObjectScope(); |
| var data = from Item in scope.Extent<EstoqueItens>() |
| join T in scope.Extent<EstoqueItensTipo>() on Item.Tipo equals T.IdTipo |
| join S in scope.Extent<EstoqueItensStatus>() on Item.Status equals S.Id |
| join Qtde in scope.Extent<EstoqueQtdItem>() on Item.Cod equals Qtde.Cod |
| where Item.Empresa == 1 |
| orderby Item.Cat descending, Item.Cod descending |
| select new |
| { |
| Cod = Item.Cod, |
| Nome = Item.Nome, |
| Info = Item.Info, |
| QtdeMin = Item.QtdMin, |
| Validade = Item.MesesValidade, |
| Empresa = Item.Empresa, |
| Categoria = Item.Cat, |
| StatusId = Item.Status, |
| Status = S.Status, |
| TipoId = Item.Tipo, |
| Tipo = T.Tipo, |
| Atual = Qtde.Qtd |
| }; |
| RadGrid1.DataSource = data.ToList(); |
I got this error
| Server Error in '/SICAI' Application. |
| Unable to cast object of type 'System.Object' to type 'OpenAccessRuntime.DataObjects.query.Node'. |
| Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. |
| Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Object' to type 'OpenAccessRuntime.DataObjects.query.Node'. |
| Source Error: |
| Line 94: |
| Line 95: |
| Line 96: RadGrid1.DataSource = data.ToList(); |
| Line 97: data = null; |
| Line 98: |
| Source File: c:\Projetos\SMA.SICAI\Fontes\SMA.SICAI\SMA.SICAI.Web\Cliente\Protegidos\Estoque\_forms\CadastroItens.ascx.cs Line: 96 |
I can put my database model here if needed
Thanks