|
-
May 11th, 2009, 11:09 AM
#1
Thread Starter
PowerPoster
Simple Linq Query
Hey,
Ok I'm working on getting to Grips with some LINQ for Database access. I've setup my DBML and database connection. I have a table called PageSettings and would like to extract all rows and then iterate through them. Can anyone provide me with a sample?
Table: Page Settings
Code:
DBDataContext DBData = new DBDataContext();
Any help appriciated
-
May 11th, 2009, 11:53 AM
#2
Not NoteMe
Re: Simple Linq Query
Code:
using(DBDataContext DBData = new DBDataContext())
{
var PageSettings = from pagesetting in DBData.PageSettings
select pagesetting
foreach(var PageSetting in PageSettings)
{
//Do Stuff
}
}
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
May 11th, 2009, 10:44 PM
#3
Re: Simple Linq Query
Of course, if you want use all rows then you don't actually need any LINQ code:
csharp Code:
using (DBDataContext dbData = new DBDataContext()) { foreach (var pageSetting in dbData.PageSettings) { MessageBox.Show(pageSetting.Name); } }
It's only if you wanted to filter or project that you'd need a LINQ query because PageSettings is already a source of all records.
Also, if you don't already have a significant investment in LINQ to SQL I'd suggest that you forget it and use the Entity Framework. I could be wrong but, as far as I'm aware, LINQ to SQL doesn't offer any advantages over the Entity Framework while the opposite is not the case. Since the creation of the Entity Framework there have been fears about the future of LINQ to SQL. Microsoft say that it won't disappear but they're unlikely to look to develop it further and I wouldn't be surprised if it does go the way of the Dodo some time soon because it's basically redundant.
-
May 12th, 2009, 04:43 AM
#4
Thread Starter
PowerPoster
Re: Simple Linq Query
Thanks Guys,
jmcilhinney, Can you provide any reference links for the Entity Framework, if what you are saying is correct that's big news!
Pino
-
May 12th, 2009, 04:59 AM
#5
Re: Simple Linq Query
jm is right. LINQ to SQL is on its death bed.
I usually use only LINQ to XML or LINQ to Objects and never felt the need to use LINQ to SQL, though it might be worth learning if ms decides to develop it furthur.
-
May 12th, 2009, 05:13 AM
#6
Re: Simple Linq Query
I haven't read too much about the Entity Framework as far as actually how to use it. I watched a dnrTV episode and then experimented. There is that whole "vote of no confidence" thing but, if you're thinking of using LINQ to SQL then that shouldn't be a worry because it doesn't address any of those issues anyway.
-
May 12th, 2009, 05:16 AM
#7
Thread Starter
PowerPoster
Re: Simple Linq Query
What I'm really doing is looking for a replacement to our current DAL (Which is SubSonic - http://subsonicproject.com/)
I've been doing some reading (Wokas New Book) and it mentions Linq to Entities. It would be interesting to see it as a comparable to SubSonic which has served us well.
-
May 12th, 2009, 05:18 AM
#8
Re: Simple Linq Query
The Entity Framework basically provides a class wrapper over the dataset so that you feel at ease working with properties/methods as you would do with normal classes.
Have a look at it here to begin:
http://msdn.microsoft.com/en-us/libr...27(VS.80).aspx
The article also shows difference between the Entity Framework and LINQ to SQL approaches and how they compare against each other.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|