LINQ query null reference exception?

For starters, I think the first query can probably be rewritten as: var bPermisos = ruc.Permisos. Where(b => b. IdUsuario == cu.Id) Beyond that, it is rather unclear what your code is doing.

You appear to be re-projecting the results you already have -- taking items of a known type and creating an anonymous type to hold them. Furthermore, the second projection is accessing a bunch of members that were not selected in the first query.

For starters, I think the first query can probably be rewritten as: var bPermisos = ruc.Permisos. Where(b => b. IdUsuario == cu.Id); Beyond that, it is rather unclear what your code is doing.

You appear to be re-projecting the results you already have -- taking items of a known type and creating an anonymous type to hold them. Furthermore, the second projection is accessing a bunch of members that were not selected in the first query.

Yes is reusing because Permisos is a table with foreing key of Cat_Perfil and Cat_Usuario, and Cat_Perfil has a foreign key of Cat_Sistema, what I want to do is show the columns of Cat_Perfil that are inside the query bPermisos but with instead of Ids, the names of that Ids in this case Cat_Sistema, plz tell me if I'm writing confusing. Thanx! – user289082 Mar 8 '10 at 19:24 Okay, the problem is that when use the select statement, you are creating a new object of type Permiso, and setting the ID values.

That object has no data from any of the other tables or any properties except the ones you specified. You can either pull that data with the query, and select the aggregates (collection properties), (or just don't use select), or you can write a second query against the other tables, passing in the IDs you got from the first query. – Jay Mar 8 '10 at 19:53 Ok now it brings the data, thanx!

Now the problem is that I can't see it, it's not binding to the datagrid, is a case of silverlight, It can be asked here? – user289082 Mar 8 '10 at 20:09 Sure, but you should create a new question specific to that issue. You can include a link to this question for reference.

– Jay Mar 8 '10 at 20:38.

This could be happening because of any of the following: cu is null One element in ruc. Permisos is null, causing the exception on b. IdUsuario If it's the latter, you can just handle this by adding: var bPermisos = from be in ruc.

Permisos where be! = null && b. IdUsuario == cu.Id // ... rest of your code.

Did that and Is not working =S – user289082 Mar 8 '10 at 19:19.

Phone = c.address. ContactItems == null? Where( ci => ci.

ContactType == ContactType. If First throws an exception because there's no one with ContactType. Where( ci => ci.

ContactType == ContactType. Note that First now cannot throw an exception anymore since i've provided a default value. Var contact = c.address.contactItems.

Where( ci => ci.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions