Hello,
I have two tables: Polls and Options:
Poll PollID, Question
Options OptionID, PollID, Answer
I want to select a Poll given its ID and all Options associated to
it.
Options should be converted to a CSV list ...
My Linq code is working but I feel I am having some redundancy in
it ... Could someone, please, check it out?
PollPaper paper = (from p in database.Polls
where p.PollID == id
select new PollPaper {
Poll = p,
Options = string.Join(", ", (from o in
database.Options
join ps in
database.Polls on o.PollID equals ps.PollID
orderby
o.Answer
select
o.Answer).ToArray())
}).SingleOrDefault();
Thank You,
Miguel 3 1634
shapper <md*****@gmail.comwrote:
I have two tables: Polls and Options:
Poll PollID, Question
Options OptionID, PollID, Answer
I want to select a Poll given its ID and all Options associated to
it.
Options should be converted to a CSV list ...
Rather than doing the conversion to CSV internally, I'd make the Poll
entity have a collection of Options - which normally the designer will
include for you anyway, assuming you've got an appropriate relationship
specified in the database.
When it's fetched the collection of Polls, each of which has a
collection of Options, you cna do the CSV conversion in memory.
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
On Sep 6, 7:30*am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
shapper <mdmo...@gmail.comwrote:
I have two tables: Polls and Options:
Poll PollID, Question
Options OptionID, PollID, Answer
I want to select a Poll given its ID and all Options associated to
it.
Options should be converted to a CSV list ...
Rather than doing the conversion to CSV internally, I'd make the Poll
entity have a collection of Options - which normally the designer will
include for you anyway, assuming you've got an appropriate relationship
specified in the database.
When it's fetched the collection of Polls, each of which has a
collection of Options, you cna do the CSV conversion in memory.
--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com
Yes, that was my first option ... however PollPaper is a wrapper that
I created around LinqToSQL class Poll.
PollPaper includes a Poll object and a string of Options.
Why? Because I am using ASP.NET MVC and I am delivering the data from
the Controller to the View.
I could use an object for options ... then on the View convert it to
CSV but then I would need to convert back to an object on the View on
form submission ...
.... because the controller would expect a list of Options.
Remember than in this case PollPaper is an wrapper that works as
ViewData of the View/Controller.
Does this make any sense?
My initial concern was more in relation to my join in the linq.
Thanks,
Miguel
shapper <md*****@gmail.comwrote:
Yes, that was my first option ... however PollPaper is a wrapper that
I created around LinqToSQL class Poll.
You can still do that, but it'll be easier to do the string conversion
having fetched all the polls + options in a single SQL query.
<snip>
My initial concern was more in relation to my join in the linq.
Exactly - if you get LINQ to fetch the Options automatically by
relating them to the polls (possibly setting extra fetch criteria -
it's been a while since I've done LINQ to SQL).
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: WebSnozz |
last post by:
Some collections are such that efficient search algorithms work on them
such as binary search if the collection is a type which is sorted.
I'm wondering how LINQ searches these collections and if...
|
by: Marc Gravell |
last post by:
In Linq, you can apparently get a meaningful body from and
expression's .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to...
|
by: shapper |
last post by:
Hello,
I have 3 SQL tables:
TagId, TagText
PostId, TagId, ...
FileId, TagId, ...
I need to, using LINQ, select all records in Tags, including the
columns TagId and TagText, but adding...
|
by: shapper |
last post by:
Hello,
I have two tables:
TagId, PostId
TagId, PostId
How can I delete, given a TagId, the record from Tags and all records
associated with it in PostTags.
|
by: d-42 |
last post by:
Hi,
I've got a many-many relationship between people and locations:
Persons {personid, namefirst, accountid}
Locations {locationid, locationname, accountid}
// many-many join table...
|
by: luowan |
last post by:
Hi
I am currently building an application on .NetCF 3.5 in C#. The
application needs to process xml files. I am thinking about using LINQ
to process XML. I wrote a piece of code to modify the...
|
by: shapper |
last post by:
Hello,
I have the following LINQ:
List<Tagtags = (from t in
database.Tags
select t).ToList();
I need to restrict my results and for that I have two parameters:
StartWidth and N
|
by: Paulo |
last post by:
Why LINQ should be used on my asp.net applications? I use C# 2.0, will I
have to move to 3.0/3.5 just because LINQ?
Tell me how to convert 2.0 code to LINQ, please. I just want to stay up to...
|
by: hrishy |
last post by:
Hi
Will LINQ be ported to Python ?
regards
Hrishy
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |