Silverlight Wishes card!

This year at RunAtServer Consulting we made our wishes card with Silverlight and DeepZoom!

Click the following link to explore our Silverlight Wishes card:
www.runatserver.com/wishes.aspx

French version here.

RunAtServer Consulting Silverlight Wishes card

DotNetShoutout
DotnetKicks

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
 
DotNetShoutout
DotnetKicks

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

DotNetShoutout
DotnetKicks

About the author

Louis-Philippe Pinsonneault is a senior .NET developer and trainer at Runatserver. He has over 10 years of experience with . NET technology. He is a certified Microsoft Certified Professional Developer (MCPD) and a Microsoft Certified Technology Specialist .NET Framework 3.5 ASP.NET Application. He also teaches ASP.NET at Technologia, Montréal. He was awarded an MVP for Device Application Developement in 2010 and 2011.

Microsoft Most Valuable Professional

Microsoft Certified Professional Developer

Microsoft Certified Technology Specialist

View Louis-Philippe's profile on LinkedIn

Page List

Month List