The following example shows how to populate the database created in the previous example with data using ODBC directly. Note that the object primary key is stored as a binary string.

            // Creating a group
            var groupId = Guid.NewGuid();

            domain.DbAccess.ExecuteNonQuery(cmd =>
                {
                    cmd.CommandText = string.Format("insert into {0}({1},{2}) values(?,?)",
                        groupTable.FullName,
                        groupTable.SystemColumns.Id.Name,
                        groupName.Name);

                    cmd.Parameters.Add(domain.DbAccess.CreateParameter("id", OdbcType.Binary, groupId.ToByteArray()));
                    cmd.Parameters.Add(domain.DbAccess.CreateParameter("group_name", OdbcType.String, "My group"));
                });

            // Reading the group name
            domain.DbAccess.ExecuteScalar(cmd =>
                {
                    cmd.CommandText = string.Format("select {0} from {1} where {2}=?",
                        groupName.Name,
                        groupTable.Name,
                        groupTable.SystemColumns.Id.Name);

                    cmd.Parameters.Add(domain.DbAccess.CreateParameter("id", OdbcType.Binary, groupId.ToByteArray()));
                },
                result =>
                {
                    Console.WriteLine("Group: name = {0}", DbValue.GetString(result));
                });
        }
}

Last edited Mar 8, 2012 at 6:22 PM by mapase, version 12

Comments

No comments yet.