Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linq transform field

Posted on 2014-09-12
3
Medium Priority
?
122 Views
Last Modified: 2016-02-15
Hi:

I have a field in a products table that I am trying to transform when it is in a list from "MyPic" to "/Content/Image/MyPic_small.png"

The Model is:
public class Product
    {
        public int ProductId { get; set; }
        public int GenreId { get; set; }
        public string Title { get; set; }
       public string PicUrl { get; set; }
        public virtual Genre Genre { get; set; }
    }

Open in new window


The current Linq expression is:
var genreModel = storeDB.Genres.Include("Products")
.Single(g => g.Name == genre);

Open in new window


My Pic is found in the field PicUrl.  Any help in figuring out how to do this in the Linq expression greatly appreciated.

RBS
0
Comment
Question by:RBS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40319896
Are you getting any run time exception? If so please post complete message.

The query if it is working will return 1 or more records for Product . If it is a collection you will need to state which one if it is a One -to-One relationship between then it will be genreModel.Product.PicUrl.
0
 

Author Closing Comment

by:RBS
ID: 40358445
Fernando:

Thanks for your response - I'm afraid I found a quick solution and then went off and did other things - and well, dropped the ball.  I think looking back on it now that I probably need to create a dto but for now don't have time and my quick solution is working.

Regards,
RBS
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40358489
Not a problem, glad to help.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question