Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Linq transform field

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
RBS
Asked:
RBS
  • 2
1 Solution
 
Fernando SotoCommented:
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
 
RBSAuthor Commented:
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
 
Fernando SotoCommented:
Not a problem, glad to help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now