Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 25th, 2011, 09:50 PM
Authorized User
Points: 173, Level: 3
Points: 173, Level: 3 Points: 173, Level: 3 Points: 173, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2011
Posts: 39
Thanks: 9
Thanked 0 Times in 0 Posts
Default Best way to concenate strings in LINQ to Entities?

I looked online and this was the best solution I could find but it's doesn't compile correctly.

     var myFight = from r in myEntity.FIGHTs
                    let WvsL = string.Format("{0} vs {1}", r.Winner, r.Loser)  
                    select new {
                    Match = WvsL,
I want to concatenate the 2 fighters names into one column called Match. My compiler error is as follows:

LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression.

What would be the best to go about this?

And I really appreciate the quick resonses so far. I have spent all of my schooling doing mostly C++ programming and this web stuff has so much syntax to learn it makes my head explode. lol
Reply With Quote
  #2 (permalink)  
Old December 26th, 2011, 05:46 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi there,

For questions not directly related to my book - such as this one - please post in a more general ASP.NET / .NET category that you can find here: http://p2p.wrox.com/asp-net-4-539/ / http://p2p.wrox.com/

That said, LINQ to EF has trouble translating the String.Format into a SQL expression. What you can do is execute a EF query first (which results in the generated SQL) and then use LINQ to Objects to concatenate the values. Using the PlanetWrox database, something like this would work:

using (PlanetWroxEntities context = new PlanetWroxEntities())
  var reviews = (from r in context.Reviews
                where r.Authorized == true
                select new { r.Id, r.Title }).ToList();
  var concatenatedRviews = from r in reviews
                           select new
                             Joined = string.Format("{0} - {1}", r.Id, r.Title)
  GridView1.DataSource = concatenatedRviews;
Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ to EF and LINQ to SQL sophia BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 19th, 2011 12:16 PM
resolving entities stolte XSLT 5 February 24th, 2011 01:31 PM
Linq Question about related entities gspro BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 March 23rd, 2010 09:29 AM
Comparing Performance Linq To entities and outofBand SQL updates urpcor BOOK: Professional ADO.NET 3.5 with LINQ and the Entity Framework ISBN: 978-0-470-22988-0 4 September 28th, 2009 06:22 AM
Entities safin XSLT 1 November 7th, 2005 04:59 AM

All times are GMT -4. The time now is 04:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.