The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Sorting by DateTime - Time Only.

Last post 04-12-2007, 10:04 PM by BUXjr. 10 replies.
Sort Posts: Previous Next
  •  03-27-2007, 3:00 PM 1443

    Sorting by DateTime - Time Only.

    I have a DateTime field where the date portion is always the same and the time portion is what is mainly stored and used.  I need to sort (order by) a collection by this field, but as the date portion is always the same, it doesn't appear to be sorting properly.  Here is the code.  Somebody please tell what I am missing...

    Dim coll As New VSchedulesCollection

    coll.Query.Where(coll.Query.Dayofweek.Equal(Me.ddlDayOfWeek.SelectedValue))

    coll.Query.OrderBy(coll.Query.TimeStart.Ascending)

    coll.Query.Load()

    With Me.dlSchedule

    .DataSource = coll

    .DataBind()

    End With

     This code appears to throw the items in to the datalist randomly, not by the time portion of the datetime field, "timestart".

     

    Thanks in advance.

    BUXjr


    Regards,

    BUXjr
  •  03-27-2007, 4:53 PM 1448 in reply to 1443

    Re: Sorting by DateTime - Time Only.

    Hey All,

     Just wanted to post that I have figured this little buggaboo out.

    Having underscores ("_") in your field names is pure evil with EntitySpaces.  The field "timestart", in the scenario above was actually in the DB as "time_start".  Despite my best efforts, this was simply NOT order-able.  So, I (on a whim) decided to try to remove the underscores from all of the field names in the DB (mostly because it was just getting confusing comparing code vs. actual field names) and voila!  All of the sudden, this query was sorting PERFECTLY.

     So, the moral of the story here is: Don't use underscores in your field names if you plan on using EntitySpaces.NET -- which you should, so don't do it!

     Hope this helps someone,

     BUXjr 


    Regards,

    BUXjr
  •  03-27-2007, 9:48 PM 1458 in reply to 1448

    Re: Sorting by DateTime - Time Only.

    That is very good advice. Unfortunately, not everyone can change their schema so easily. Thanks for pointing this out. We'll have to look into this and follow through.
    David Neal Parsons
    www.entityspaces.net
  •  04-12-2007, 11:35 AM 1761 in reply to 1458

    Re: Sorting by DateTime - Time Only.

    Hey David,

    Yeah, I hear ya.  I'm actually looking at converting an existing web-app over to ES, but the existing DB is LOADED with "underscored" field names.  So many that it would most likely be a deal-breaker to have to rename them all.  Especially since the conversion to ES from their existing DAL is likely to take several days to complete.  Changing the DB schema would break the current version of the site, until the new one could be released.

    So, that being said...is there any insight into why ES has such problems with underscored field names?  Is there something that could be done to make this not such a "no-no"?  Perhaps a quick change in the templates?  LMK if there is ANY light you can shed on this topic.  I would really love to do this conversion but simply cringe at the thought of having to change the schema.

    By your command...

     


    Regards,

    BUXjr
  •  04-12-2007, 11:51 AM 1762 in reply to 1761

    Re: Sorting by DateTime - Time Only.

    I suppose the first question to be addressed here is, "Why does Entity Spaces take it upon itself to remove underscores from field names"?  Is there a compelling reason for this?  Is there some underlying problem with field names containing underscores that made you guys decide to strip them out?  

    Because it appears that it's this disparity between the field names in the classes/collections and the real field names in the actual db schema that is causing the breakdown in databinding and sorting.  I've used other DAL / ORMapping (admittedly none that are better than ES but some that worked, ie RapTier, etc...) apps and utils before that had no problem with them and left the field names intact...

    Thoughts?


    Regards,

    BUXjr
  •  04-12-2007, 12:03 PM 1763 in reply to 1762

    Re: Sorting by DateTime - Time Only.

    There are just a couple of bugs in here that we missed. Our next beta will have these issues worked out. There is an option in the esPlugin Settings template called "Use Raw Names" that will allow you to use the raw database names. However, it's just an oversight, it will be fixed in the next beta. We apologize for this but we will fix it.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-12-2007, 12:17 PM 1764 in reply to 1763

    Re: Sorting by DateTime - Time Only.

    Hey Mike,

    Wow -- thanks for the quick reply.

    So, you are telling me that if I put a check in the "Use Raw Names" checkbox in the esPlugin Settings, ES will not remove the underscores from my field names when it generates the classes/collections?  If this is the case, then this is the "holy grail" for me.

    If this is a solution to the problem, why does it say "(Not Recommended)" beside that checkbox?  That is a little frightening to me...  What about that is "not recommended"?  Will I botch something else by enabling that feature?

    Sorry to blather on about this, but if this works I'll be poopin' in tall cotton.  Again, thanks for your assistance.  You guys are great at communicating with your users.


    Regards,

    BUXjr
  •  04-12-2007, 4:05 PM 1767 in reply to 1764

    Re: Sorting by DateTime - Time Only.

    We don't have anything against underscores. What we are doing by default is PascalCasing exposed Class, Method and Property names as is recommended in Microsoft's naming guidelines. UseRawNames is not recommended for that reason and because there can be a lot of things in a table or column name that will cause VB or C# to choke. You can adjust the TrimList in esPlugin if you UseRawNames and have some compile errors because of illegal characters. You can also use MyGeneration's User Meta Data to Alias table or column names that still need tweaking.

    You have a lot of options available, but the bottom line is that underscores should not be causing any problems when we PascalCase, and that will get fixed.


    David Neal Parsons
    www.entityspaces.net
  •  04-12-2007, 6:12 PM 1770 in reply to 1767

    Re: Sorting by DateTime - Time Only.

    Hey Dave,

    Thanks again, for getting back to me in such a timely manner.

    Ha!  I didn't think you guys had anything "against" underscores, but was just curious as to your reasoning for removing them as regular practice.  Now I understand WHY you are doing it -- is the MS way.  Not just 'cause you think they're ugly or something...  =)

    So, as long as I know that I have NO illegal characters in my field names (save, the underscores) I should not worry about using "Use Raw Names"? 

    This would really make life a lot easier.  I'm very to happy have heard of this option.  Thanks for sharing.

     


    Regards,

    BUXjr
  •  04-12-2007, 9:51 PM 1773 in reply to 1770

    Re: Sorting by DateTime - Time Only.

    UseRawNames should be fine as long as you understand the possible ramifications.

    To clarify further, there is nothing bad about underscores in names. It was a long time before I understood why MS specifically prohibited them and FxCop will complain about them. It turns out the only reason we Developers are not supposed to use them in public and protected names is because Microsoft uses them in their generated names! Take a look at the names generated by the forms Designer - Demo_Load, buttonExit_Click, etc., etc. Microsoft is reserving all names with underscores for themselves. By denying their use to us, they eliminate possible naming collisions.

    But, this prohibition does not extend to private instance fields, and FxCop will not grouse about them. A publicly exposed PascalCased Property (e.g; ConnectionName) backed by a CamelCased private instance field prefixed with an underscore (e.g.; _connectionName) is a widely practiced convention that is still perfectly valid.

    http://www.irritatedvowel.com/Programming/Standards.aspx


    David Neal Parsons
    www.entityspaces.net
  •  04-12-2007, 10:04 PM 1776 in reply to 1773

    Re: Sorting by DateTime - Time Only.

    DNP,

    As usual, your brilliance is enlightening.  Thanks for the insight.

    When it comes to MY use of underscores in field names, I pretty much use them EXCLUSIVELY in primary key and foreign key names.  Like, "pk_member" and "fk_league", etc.  However, there is an occasional slip up when an underscore gets used in a bad place like, "start_date" or "is_active".  Seems prudent to ween myself from these practices anyway. 

    The problem is more like when you "inherit" a database as the result of taking on a new job/project and you find that the database's original architect has an almost religious belief in the use of underscores...  =)

    At any rate, I'll give it a try and let you know if anything wierd pops up.  I'm sure it'll be fine.

    Thanks again for the quick and intelligent reply.  This type of support and communication is a rare commodity in today's landscape.  Keep up the good work.  You've found a STRONG believer here.


    Regards,

    BUXjr
View as RSS news feed in XML