subsonic / SubSonic-3.0-Templates

T4 Template Project for the peeps
http://subsonic.github.io/
105 stars 46 forks source link

SimpleRepository does not correctly generate table on SqlServer with Int64 Columns #56

Open feihtthief opened 13 years ago

feihtthief commented 13 years ago

Below is a program demonstrating the bug(s)

Step to reproduce: Run Program to induce bug. Expected Result: Both columns for ID and RefID to be created as bigint columns. Actual Result: They are created as int columns

Additional Steps: Change column Types to Bigint in Database. Rerun Program Expected Result: Expect the columns For ID and RefIT would be left as bigint. Actual Result: ID Column remained bigint, but RefID migrated back to int.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.DataProviders;
using SubSonic.Repository;
using SubSonic.SqlGeneration.Schema;

namespace DemoInt64Bug
{
    [SubSonicTableNameOverride("Demos")]
    public class Demo
    {
        [SubSonicPrimaryKey]
        public long ID { get; set; }
        public long RefID { get; set; }
        [SubSonicNullString]
        public string Name { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var provider = ProviderFactory.GetProvider(@"Data Source=.\sqlexpress;Integrated Security=true;Initial Catalog=Tinker;", "System.Data.SqlClient");
            var repo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);

            var demo = new Demo{Name = "foo"}; 
            repo.Add(demo); 
            // This works, but creates table with two int columns instead of two bigint columns
            // Also, if you change the columns to bigint, the next migration will turn the second column back to int, but not the first ?!?

            Int64 id = demo.ID;
            var demoBack = repo.Single<Demo>(id); // fails, and spews a error message about sqlite, but that error would be the opposite direction :S
        }
    }
}