Column named Date_Time causing problems

Sep 30, 2009 at 10:19 AM

Hi, since NHydrate likes to remove the underscores and create nice looking names on things. I got a problem with a column name like DATE_TIME beeing transformed to DateTime... which obvious is a problem.

Coordinator
Sep 30, 2009 at 12:15 PM

Hello and thanks for your response. The underscores are fixed and I assume you do not want change the name of your field. Well then you will need to use the codefacade property. It allows you to keep the database name you want but change the name in code. On the field property sheet, above the name, change codefacade to some other value. I am sorry you cannot keep DATE_TIME in code but this does allow you to keep your database name unchanged if that is your goal.

Oct 1, 2009 at 7:42 AM

Keeping the name DATE_TIME in my code is not that important but in my case the Date_Time column is a varchar column and in code it ends up like tablename.DateTime = DateTime.Now; and since my DATE_TIME column is "renamed" DateTime an overload is created to the real DateTime type
and this leads to "Error 207 'string' does not contain a definition for 'Now' and no extension method 'Now' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) "
You probably need som more validation rules to fix issues lite this.

Another thing I noticed was that a generated sp used ntext, why not use nvarchar(max) instead?

I got one more question. Why use database transactions? and why not TransactionScope from System.Transaction?    

 

Coordinator
Oct 6, 2009 at 10:46 AM

First to the original problem

I am unable to reproduce the issue. I have created a test model with the following

One table known as TEST_TABLE
Two Columns:

test_table_id - primaryKey="True" generated="True" identity="0" name="test_table_id" codeFacade="" description="" dataFieldFriendlyName="" dataFieldVisibility="False" dataFieldSortOrder="0" default="" length="16" isIndexed="False" isUnique="True" id="3" type="14" allowNull="False" min="NaN" max="NaN" isSearchable="False" mask=""

date_time - primaryKey="False" generated="True" identity="0" name="date_time" codeFacade="MyDateTime" description="" dataFieldFriendlyName="" dataFieldVisibility="False" dataFieldSortOrder="0" default="" length="100" isIndexed="False" isUnique="False" id="2" type="22" allowNull="True" min="NaN" max="NaN" isSearchable="False" mask=""

This model generates and works with the following example code

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigurationValues.GetInstance().ConnectionString = "Data Source=localhost;Initial Catalog=TestDb2;User=sa;PWD=database;";

            TestTableCollection ttc = new TestTableCollection("Mike");
            TestTable tt = ttc.NewItem();
            tt.Mydatetime = "2009/02/02";
            ttc.AddItem(tt);
            ttc.Persist();

            TestTableCollection ttc2 = TestTableCollection.RunSelect("Mike");
            foreach (TestTable temp in ttc2)
            {
                Console.WriteLine(temp.Mydatetime);
            }

            Console.ReadKey();
        }
    }
}

Is there a way you can email an example model to describe your problem:  mknight@widgetsphere.com.

 

Another thing I noticed was that a generated sp used ntext, why not use nvarchar(max) instead?

There is currently no support for nvarchar(max). Primarily because the product is still compatible with SQL 2005. We will look into supporting this in the next release.

I got one more question. Why use database transactions? and why not TransactionScope from System.Transaction?

The reason for this is historical. There is currently not a good reason for us to change to TransactionScope. Please let me know the reason you would like this feature and we can look into a possible change.

Oct 7, 2009 at 8:42 AM

Ok, now I see how I could change my codeFacade="MyDateTime" this will solve my problem the with "date_time" column. I still think the checking rules should find this problem...

Regarding nvarchar(MAX) I guess you mean SQL2000, SQL2005 have support for nvarchar(MAX), but If you need (want) to support SQL2000 I can understand. (It was only a suggestion)

Also regarding the transactions, my reason for using TransactionScope over sql transactions is that it is a more generic transaction model that supports other transaction resources than just SQL server. (you might want to include msmq or something else in your transaction)

Coordinator
Oct 8, 2009 at 4:08 PM

Thank you so much for the information.

I will bring up nvarchar(Max) and Transaction Scope during the development meeting.

Transaction Scope will most likely be taken up as we start to support preselect, postselect, preupdate, postupdate services.

 

Apr 20, 2010 at 10:17 AM

I also found that

1 - I can't call field by "Date" in the table.(Error Message on Verify stage)

2 - I also can't call my Table as something like "crs_Collection"(Error Message on Verify stage)

Tell please   When these problems can be solve?

Coordinator
Apr 20, 2010 at 3:27 PM

"Date" is a reserved word and cannot be used as a token. The reason "crs_Collection" cannot be used is to avoid confusion. A class named [table]Collection will be generated and your table name would make an object name "CrsCollection" as the singular and "CrsCollectionCollection" as the plural. Table names should be singular or at the very least the code facade should be singular if you have an existing table and you cannot change the name. This rule is enforced to avoid confusion when you are writing code.

Coordinator
Dec 3, 2010 at 2:59 AM

Some of this information is not valid now. The model property TransformNames determines if the whole underscore transformation takes place. This is off by default, so your code name will match your odel names by default.

Dec 28, 2010 at 5:55 PM

I'm new to nHydrate and I want to use it to connect to an existing database. I've tried to import a model but keep getting errors when i want to connect to an SQL-server. The SQL-server is local and i've tried to use a '.' as well as my local ip. normally i log on as 'sa' and that wouldn't work so i tried to log in under my windows account as well (which works on my 'sql enterprise manager') and that doesn't work either. I tried to use the connection string (that my application uses with succes as well) but still i can't connect. The error i keep getting (when i press the import button in the wizard) is 'The connection information is invalid'. It's a bit frustrating because i searched for a long time to find my ideal generator and i thought i found it :(.

Coordinator
Dec 29, 2010 at 5:09 PM

This issue was solved by identifying that the user imported from SQL 2000. This is a not a supported database platform. nHydrate supports SQL 2005 and above.

Coordinator
Jan 1, 2011 at 2:28 PM

The next version will check the SQL version before import and prompt an error if less than 2005. This will remove the confusion of why models do not import.