About 10 on a TRS-80, trying to create my own versions of Adventure and Haunted House. From there, moved onto PIMS, their first database. :-D
User 2689127
Posts
-
How old were you when you first wrote a line of code ? -
How To Test If Linq Query Returned ResultsThanks Gideon - I hadn't used Any for that purpose. Awesome tip!
-
How To Test If Linq Query Returned ResultsJust reading this and thought I would jump in. I typically use query.FirstorDefault to verify it. You could also use query.Count>0 However, I tried some sample code and got that message when I hadn't instantiated my datacontext properly. That may not be it but just something to verify.
-
Stupid Naming Consequences with LINQHere's another good reason not to use reserved names. I'm working on a LINQ project with a series of tables that manage user roles. As a result, I have table names like Systems, Roles and Users. My trouble started when I would add the objects to the Designer, hit Save and then suddenly Visual Studio would say things like System.Data.Linq.Mapping.DatabaseAttribute is not defined or System.Nullable is not defined In short, stopping me dead in my tracks. Now that I look back, I don't know why I didn't see the reason earlier. When using the Object Relational Designer, Visual Studio wants to be smart and changes any words that are plural to singular so they make more sense when dealing with data. That way, your code looks like
oUser = New User oUser.UserName = "John"
instead ofoUser = New Users
This is really nice because it does make the code a little more legible except in this situation: Plural (singular) Users (User) Roles (Role) UserRoles (UserRole) Systems (System) See the gotcha? Visual Studio translated the "Systems" table into a "System" object which immediately negated all of the main namespaces in the project. The renaming feature for the objects in LINQ-to-SQL is great - but be warned, when you start getting errors like this, take a look at your source tables.