LP Pinsonneault blog's

Windows 8, Windows Phone, ...

NAVIGATION - SEARCH

Casting issues with Linq and Entity Framework

Recently i was working on a project where i was using Entity Framework as the data layer. It's the first project i'm working with it. In one of my query I wanted to output some fields merge in one fields like the following query:

[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable GetListJoueursByClubId(int clubId)
{
    var query = from joueur in this.Joueurs
                where joueur.Clubs.Id == clubId
                orderby joueur.Clubs.Nom
                select new { Id = joueur.Id, NomComplet = joueur.Nom + ", " + joueur.Prenom
                                                          + " " + (joueur.Numero ?? 0) };
    return query; 
}
 
But I was always getting errors related to casting.
image
 
 
There was many solutions that could be applied. But one solution to solve the issue at the query level, it's to use a sub query. This way the first query will be executed in memory, and Linq will know the type of the object we are working with and Linq will be able to cast the object properly.
 
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable GetListJoueursByClubId(int clubId)
{
    var query = from joueur in this.Joueurs
                where joueur.Clubs.Id == clubId
                orderby joueur.Clubs.Nom
                select new { Id = joueur.Id, 
                             Nom = joueur.Nom, 
                             Prenom = joueur.Prenom, 
                             Numero = joueur.Numero
                            };

    return from joueur in query.ToList()
           select new { Id = joueur.Id, NomComplet = joueur.Nom + ", " + joueur.Prenom 
                                                     + " " + (joueur.Numero ?? 0) };
}
 
I hope this will help you, if you face this kind of issue.
 
 
Regards,
Louis-Philippe
 

Happy New Year!

I want to take some times to wish all of you an happy new year and i hope this new year will bright health and success to everyone.

For my part, I don`t take any resolution but I prefer to fix myself some objective. Some of those objective are to gain new certification (WCF 3.5), upgrade my current MCPD certification for ASP.NET 3.5 and work on some Silverlight project.

Happy New Year!

Louis-Philippe

My experience at Speaker Idol

Hi,
Yesterday night was a great night. I've participated to the Speaker Idol hosted by the Montréal .NET Community. That was the first time i ever did a presentation in front of people since high school. There was great subjects present by the other presenters. I didn't win, but i've accomplish my goal with proud. So now the glass is broken. We had only 10 minutes to present our subject, that was not easy to do.

I was there to kick my butt and do the experience. I can say that i learn a lot.

I want to thanks all the presenter, the judge for the precious hint that will help us do better presentation and all the people that came to see us.

As i say, here is the Powerpoint of my presentation and the solution files:
-Powerpoint
-Project

 

Best Regards,
Louis-Philippe

Speaker Idol - Montréal .NET Community

Hi everyone in the Montréal region,

don't forget to come see us at the Speaker Idol (November 3rd, 2008 at 6:15pm to 9:00pm) which is a contest that will take place at the Montréal .NET Community. I will participate by doing a presentation on "How to communication between two Silverlight applications in the same page". I hope my presentation will go well. It's the first time i'm doing this kind of thing. Personally, it will be a good exprience because it's part of personal goal. Also i want to be more present in the .NET community.

So after my presentation i will post the powerpoint slides and my sample project on this blog.

Also another of my colleague from RunAtServer, Bruno Pelletier will also participating by doing a presenting using Microsoft Expression Blend to create Silverlight animation.

Have a nice weekend, and i hope to see you there.

Louis-Philippe

My first time blogging!

First,  I will present myself. my name is Louis-Philippe Pinsonneault.  As you will see I'm passionate about web technologies (ASP.NET, Silverlight,...). I'm currently working for RunAtServer Consulting since September. I'm working at Montreal. I have up to 8 years of experiences with the .NET Framework. I focus myself on ASP.NET application and now on Silverlight.

During the last year, I acquired some Microsoft certification (MCPD Web Application, MCTS .Net Framework 2.0: Web Applications and MCTS .NET Framework 3.5, ASP.NET Applications). Currently, I'm looking forward to get the following certifications MCTS: .NET Framework 3.5,Windows Communication Foundation and MCPD: ASP.NET Developer 3.5.

MCPD(rgb)_504 MCTS(rgb)_1102_513   

 

So you may expect to read information's about ASP.NET, Silverlight, WCF and other .NET technologies.

 

I hope you will enjoy reading my blog.

Best Regards,

Louis-Philippe