SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Linq Query of added properties

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linq Query of added properties

    I've added properties to my Linq classes as such:

    Code:
            Public Property Status() As UCRStatus
                Get
                    Return Me.dbStatus
                End Get
                Set(ByVal value As UCRStatus)
                    Me.dbStatus = value
                End Set
            End Property
        End Class
    
        Public Enum UCRStatus
            [Closed] = 0
            [BranchManager] = 1
            [Client] = 2
        End Enum
    I've named my Linq entity property dbStatus and set it to Protected Access because I want my clients to use this Status property and the associated Enums. Works beautifully.

    Until I want to query on the Status. Then I, understandably, get the error that says there's no mapping to SQL.

    Without opening up my raw database field for manipulation, is there a way I can teach Linq to deal with or map this property in a way that "where x.Status = UCRStatus.BranchManager" ? Or maybe there's a better way to go about this overall?

    Thanks in advance for the insight.

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a better way, ditch Linq2Sql and check out FluentNHibernate http://fluentnhibernate.org/

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me rephrase my question:

    "I'm looking for a framework that will support object-oriented queries against added object properties, any suggestions?"

    Sorry, I thought I asked a Linq question.

    "My car pulls to the left, what can I do?"
    "Throw it away and buy a motorcycle because that's my preference"

    Excellent.

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was answering:

    Or maybe there's a better way to go about this overall?
    :P

    If you are going to stick with linq2sql, then this might be what your looking for: http://dotnet.org.za/hiltong/archive...nq-to-sql.aspx

  5. #5
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And in response to this
    "My car pulls to the left, what can I do?"
    "Throw it away and buy a motorcycle because that's my preference"
    Your a little wrong, they are both solving the same problem, just NHibernate is far superior and hasn't been canned. So:
    "My car pulls to the left, what can I do?"
    "Throw it away and have a free Ariel Atom, you'll have great fun!"

  6. #6
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,748
    Mentioned
    17 Post(s)
    Tagged
    0 Thread(s)
    I agree with dhtmlgod on this 1. Except for one point. Linq2Sql has not been canned. As 2 many ppl where complaining about the dropping of linq, so MS has decided to continue with it.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dropping of Linq? I never heard of that! Is that in favor of going with Entity Framework or just dropping the whole idea? Any links to this news?

    Anyhow, I'm closer to my answer but now hung up on a further point. I've eliminated the property in my partial class extension and I'm back to using the generated Linq property but in the O/R Designer, I'm specifying that the property type should be that of my Enum. This seems to work well as subsequent Googling has informed me that Linq will map from the Int DB field to the Integer Enum type. If I do a Linq query, I can indeed query and set/get using my enum.

    So that actually answers my original question.

    The hang up, and it's relatively minor, is that when binding my resultset to a gridview, it doesn't pick up this field when it autogenerates columns. It does work if I manually create the gridview column and bind the property to it. Does anyone know why it doesn't pick this up in autocreate? Seems to me that it's a first-class Linq return column and the generated property has teh same attributes as other fields, so it should be flagged as data-bindable, etc. Any ideas?

  8. #8
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,748
    Mentioned
    17 Post(s)
    Tagged
    0 Thread(s)
    Yes, linq was being dropped in favor of the entity framework, but a lot of people were not happy and complained about it, so the reconsidered and decided to rather continue with it. I will try later to find the links for you.

    PS. Sorry I cnt help with your other problem. I have never come across this b4 as I never autogenerate colums and i use PLINQO, which is codesmith version of linq to sql. It generates the dbml and managers and entities i need and maps everything i need.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •