Skip to content

LINQ

LINQ (all flavours)

This category can be followed from the open social web via the handle linq-e04cf296@forum.codeproject.com

783 Topics 2.8k Posts
  • Images, Databinding and Linq

    database question csharp css linq
    5
    0 Votes
    5 Posts
    5 Views
    J
    Hi guys, I thought i'd post my solution to the question I asked the other day. I know linq is still pretty new to a lot of us and there isn't that much documentation out there regarding working with images. What my code does is looks via a httphandler on my database for an image in column image1 in the tblImages table. If there is no result for the query then the code looks for an image stored locally in an /Images/ folder and places an alternative image. It seems to be lightning fast on my local machine though i've yet to try it online. Anyhoo, Apologies for the formatting, VS to Notepad to CP doesn't look nice......I hope this helps someone out there. ;) The http handler ---------------------------------------------------------------------- Public Class PhotoHandler Implements System.Web.IHttpHandler Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest If Not String.IsNullOrEmpty(HttpContext.Current.Request.QueryString("ImageID")) Then Dim Name = HttpContext.Current.Request.QueryString("ImageID") Try Dim result = GetPhoto(ImageID) If result IsNot Nothing Then HttpContext.Current.Response.BinaryWrite(CType(result.ToArray, Byte())) context.Response.End() Else Dim photo As Stream = PhotoManager.GetPhoto() Dim buffersize As Integer = (1024 * 16) Dim buffer() As Byte = New Byte((buffersize) - 1) {} Dim count As Integer = photo.Read(buffer, 0, buffersize) Do While (count > 0) context.Response.OutputStream.Write(buffer, 0, count) count = photo.Read(buffer, 0, buffersize) Loop End If Catch ex As Exception End Try End If End Sub ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return True End Get End Property End Class ---------------------------------------------------------------------- My Functions ---------------------------------------------------------------------- Imports System.IO Public Class PhotoManager Public Overloads Shared Function GetPhoto() As Stream Dim ptpath As String = HttpContext.Current.Server.MapPath("~/Image
  • Statement about LINQ

    database csharp linq com design
    4
    0 Votes
    4 Posts
    2 Views
    C
    I'm not going to repeat what others have said, so I'll just add this: It sounds like he is talking about LINQ to Entities (which is only at CTP stage at the moment) rather than LINQ to SQL. LINQ to Entities is the ORM tool that Microsoft are bringing out. It looks quite neat, but I've yet to try it. WRT performance degredation, a good DBA will be able to write more performant stored procedures that match the database than an ORM tool will write SQL Queries. If the database changes the sprocs can be updated and the application need never know. If you change the data model then the application may need to be regenerated (or at least the mapping files need to be redistributed in the case of LINQ to Entities*) With my DBA hat on, I still prefer stored procedures, because then access to and modification of the database is controlled from within the database. Giving away rights to access tables directly is not something I am keen on from a security stand-point. I don't trust developers (even although with a different hat I am one) with my database. Trust is earned and so far the vast majority of developers have been found wanting. Also, take in to account that database security is difficult, and even although you might start out with the best of intentions the number of systems I've seen where a security problem is eventually resolve with the ah-phukkit-lets-just-make-it-dbowner method of sorting out access problems is heart-breaking** So, personally, I'm in turmoil on this. I really like the idea of LINQ to SQL and LINQ to Entities from a developer stand point, but the database administration in me says "You ain't gettin' your dirty paws on my database!" * Again, I've not used it, so this information may be used by the compiler rather than the runtime - I don't know, but many ORM tools use mapping files at runtime. ** No pun intended. Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) My website | Blog
  • New to LINQ

    database csharp sharepoint linq
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • Recursive LINQ

    csharp linq question
    3
    0 Votes
    3 Posts
    2 Views
    M
    Well I'm tempted not to give specifics of the problem, largely because it's the theory I want to get straight in my mind, rather than just getting an answer to the current problem. However: Say I want to loop through directories and report the names of sub-directories (and sub directroies and sub directories....) is this possible with Linq? Maybe a Func can be used (although I can't see how you call the Func from within itself)?
  • 0 Votes
    5 Posts
    7 Views
    P
    Damn but you're right. I'd missed that he was asking about Dynamic LINQ. Deja View - the feeling that you've seen this post before. My blog | My articles
  • Changing table name at run time!!

    database csharp linq com tools
    4
    0 Votes
    4 Posts
    2 Views
    P
    Try here[^]. Deja View - the feeling that you've seen this post before. My blog | My articles
  • Returning a LINQ query

    database question csharp linq design
    3
    0 Votes
    3 Posts
    3 Views
    1
    Thanks for taking the time to reply mate, but I've just figured it out! It was a long day, doing to many things at once, and I suffer from a rare stupidity based disease called 'Code blindness'. ;)
  • How "XDocument.Descendants" work? [modified]

    csharp database linq com xml
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • From typed DataSets to LINQ.... hmmm.

    csharp database visual-studio linq business
    2
    0 Votes
    2 Posts
    4 Views
    A
    I found the solution, thanks to the magic of Extension methods. (They kick ass!) I decided to move my TableAdapter methods as extension methods of the IQueryable<_Entity_> class. So now for example, my User methods are inside their own class and they take this IQueryable<User> as the first parameter, like this: public static User GetByEmail(this IQueryable<User> users, string email) { return users.SingleOrDefault(u => u.Email.ToLower() == email.ToLower()); } This allows me to then say in my Business code: var user = dataContext.Users.GetByEmail(email); It's cool stuff because extension methods basically allowed me to modify the Users property of the DataContext from the outside, and keep all the user-related data-access logic neatly organized like it was before inside the TableAdapter. Cheers! Al - Is God willing to prevent evil, but not able? Then he is impotent. - Is he able, but not willing? Then he is malevolent. - Is he both able and willing? Whence then is evil? - Is he neither able nor willing? Then why call him God? Epicurus
  • 0 Votes
    3 Posts
    3 Views
    J
    Eduard Keilholz wrote: I want to be able to sort ascending or descending depending on a boolean called lets say bSortAscending. When the boolean is true, sort Ascending, else descending. Remove the whole orderby clause from your LINQ query. Then do var ordered = bSortAscending ? qMessage.OrderBy(...) : qMessage.OrderByDescending(...); Eduard Keilholz wrote: Is there a way I can retrieve fieldnames from my datasource (SQL Server) from the datacontext? That I don't know. Perhaps someone else can help you with this.
  • Scat object ref

    database question
    2
    0 Votes
    2 Posts
    3 Views
    J
    Sorry, that won't work unless you use ref. Do this instead: Item loadedItem = LoadByItem(item.Id); ... private Item LoadByItem(int id) // if Id is not an int, change this accordingly {     var matches = from item in new MyDBDataContext().Items                where item.Id == id                   select item; return matches.First(); } Tech, life, family, faith: Give me a visit. I'm currently blogging about: I'm Offended That You're Offended! The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
  • Select Distinct in LINQ

    csharp database linq help
    2
    0 Votes
    2 Posts
    2 Views
    P
    Take a look at the Except operator. Deja View - the feeling that you've seen this post before. My blog | My articles
  • 0 Votes
    7 Posts
    6 Views
    R
    >>Ofcourse We Know That Writing String Command need To Be compiled On Sql Engine But Is Linq Query Statment Need And What Is The Strory About that The true story is that if you worry about the performance on compiling sql statements on the sql server, then you are focusing and worrying about the wrong stuff. Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com
  • ASP.NET / LINQ article you may like...

    csharp business asp-net database linq
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • Linq Data Source orderby problem

    csharp linq com help
    2
    0 Votes
    2 Posts
    2 Views
    E
    Separate with a comma. See it here[^]. Eslam Afifi
  • LINQ to SQL Performance & Resources

    database question csharp linq business
    6
    0 Votes
    6 Posts
    7 Views
    P
    Eduard Keilholz wrote: Thanks for your reply! No problem. I faced this issue myself a while ago and it caused me a lot of grief looking for the solution. I wouldn't want anyone else to go through the same problems. Deja View - the feeling that you've seen this post before. My blog | My articles
  • Linq's Got Issues

    csharp database linq
    1
    0 Votes
    1 Posts
    1 Views
    No one has replied
  • LINQ on ListView.Items (ListViewItemCollection)

    csharp linq question
    2
    0 Votes
    2 Posts
    3 Views
    I
    You could do it like: listView1.Items.OfType<ListViewItem>().ToList().ForEach(x => x.Checked = true); It's not that elegant as there isn't a Enumerable.ForEach there's a static one for arrays, and one built in for List though. Edit: You could use OfType().All() however it takes a predicate and returns those matching it. Changing the input could get confusing and if you change a property that's not a bool it would get messy. modified on Sunday, April 6, 2008 11:16 PM
  • DataBinding and Filtering

    linq csharp wpf wcf algorithms
    7
    0 Votes
    7 Posts
    7 Views
    T
    Heh, nope. I just hate DataTables. Had to re-write all my logic with (string)row["field"] == blahblah etc. ------------------------------- Carrier Bags - 21st Century Tumbleweed.
  • Linq to SQL help please!

    database help csharp linq design
    8
    0 Votes
    8 Posts
    4 Views
    P
    Well done you. :laugh: Deja View - the feeling that you've seen this post before. My blog | My articles