Solved

Linq transform field

Posted on 2014-09-12
3
103 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
Comment Utility
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
Comment Utility
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
Comment Utility
Not a problem, glad to help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

8 Experts available now in Live!

Get 1:1 Help Now