OverMars
OverMars

Reputation: 1049

ORMLite only creates ID columns - SQL Server

I am fairly new to ormLite using C# and I have come across an issue where ormLite is only creating my primary key and foreign key columns and non of the public data columns of any type. Any insight or directions? Here is a code snippet:

C# Class:

    public class Person : Entity
{
    [AutoIncrement]
    public int PersonID { get; set; }

    [References(typeof(Entity))]
    public int EntityID { get; set; }

    public string FirstName;
    public string Middlename;
    public string LastName;

    public DateTime BirthDate;
    public char Gender;
    public int Age;

    public Color EyeColour;
    public Color HairColour;

    public Person(string firstName, string lastName, char gender, DateTime? birthDate = null, int? age = null, Color? eyeColor = null, Color? hairColour = null, string middleName = null)
    {

    }
}

Created using:

private IDbConnection CreateConnection()
    {
        OrmLiteConnectionFactory dbFactory = new OrmLiteConnectionFactory("Server=server;Database=mso;User Id=sa;Password=pw![enter image description here][1];", SqlServerDialect.Provider);
        IDbConnection dbConnection = dbFactory.Open();
        return dbConnection;
    }

    public TaskOutcome CreateDBSchema(params Type[] types)
    {
        try
        {
            IDbConnection db = CreateConnection();

            using (var tran = db.BeginTransaction())
            {

                db.CreateTableIfNotExists(types);

                tran.Commit();
            }
            return new TaskOutcome(new TaskOutcomeType(TaskOutcomeType.TaskResult.Success));
        }
        catch (Exception msg)
        {
            return new TaskOutcome(new TaskOutcomeType(TaskOutcomeType.TaskResult.Failure, msg.Message));
        }
    }

This is what the table structure looks like:

enter image description here

It is blocking further development so any help is greatly appreciated!

Sam

Edit: (incase its helpful)

        public string GetData(int value)
    {
        ServiceData service = new ServiceData();

        // create in order of dependecy
        Type[] types = new Type[15] { typeof(Entity), typeof(Organization), typeof(Person), typeof(Daycare), typeof(Caregiver), typeof(Child), typeof(Parent), typeof(Doctor), typeof(EmergencyContact), typeof(Contact), typeof(Country), typeof(Province), typeof(City), typeof(Address), typeof(Timesheet) };

        TaskOutcome result =  service.CreateDBSchema(types);

        return string.Format("You entered: {0}", result.ToString());
    }

Upvotes: 0

Views: 133

Answers (1)

Bhushan Firake
Bhushan Firake

Reputation: 9448

You are missing {get ; set;} for other fields.

Upvotes: 2

Related Questions