ORMLite仅创建ID列 - SQL Server

时间:2013-12-05 00:59:25

标签: c# sql-server ormlite-servicestack

我对使用C#的ormLite相当新,我遇到过一个问题,其中ormLite只创建我的主键和外键列,而不是任何类型的公共数据列。任何见解或方向?这是一段代码:

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)
    {

    }
}

使用:

创建
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));
        }
    }

这就是表结构的样子:

enter image description here

它阻碍了进一步的发展,所以非常感谢任何帮助!

萨姆

编辑:(有帮助)

        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());
    }

1 个答案:

答案 0 :(得分:2)

其他字段缺少{get ; set;}