Solved

Linq transform field

Posted on 2014-09-12
3
104 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
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 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 62

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Entity Framework 7 32
I need help making a collection from a class in VB.Net 3 27
Crystal reports vb.net 2 20
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now