Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUID issues #69

Open
martinRocks opened this issue Jun 3, 2024 · 1 comment
Open

GUID issues #69

martinRocks opened this issue Jun 3, 2024 · 1 comment

Comments

@martinRocks
Copy link

Hi,
I love your library. Would it be possible to add a mapping for GUIDs? We store GUIDs in an oracle RAW 16. Why oracle doesn't have a specific field type for GUIDs, I don't understand. However, I need to convert the byte array to GUID. And in my case, I have to do Endian flip. I don't know if others have to do this Endian flip.

Below is an example of what I am doing. The AWN_SA_ID is the column name that is mapped by dapper. AwnSaId is the guid that I actually use.

public class Dto
        {
            public byte[] AWN_SA_ID
            {
                set => AwnSaId = FlipEndian(new Guid(value));
            }
            public Guid AwnSaId { get; set; }
            public string Jcn { get; set; }
            public string Hsc { get; set; }
        }

        private static Guid FlipEndian(Guid guid)
        {
            var newBytes = new byte[16];
            var oldBytes = guid.ToByteArray();
            for (var i = 8; i < 16; i++)
            {
                newBytes[i] = oldBytes[i];
            }

            newBytes[3] = oldBytes[0];
            newBytes[2] = oldBytes[1];
            newBytes[1] = oldBytes[2];
            newBytes[0] = oldBytes[3];
            newBytes[5] = oldBytes[4];
            newBytes[4] = oldBytes[5];
            newBytes[6] = oldBytes[7];
            newBytes[7] = oldBytes[6];
            return new Guid(newBytes);
        }

public void DapperStoredProcedure()
        {
            List<Dto> data;
            var connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
            using (var connection = new OracleConnection(connStr))
            {
                var values = new OracleDynamicParameters();
                values.Add("i_uic", Uic, OracleMappingType.Varchar2, ParameterDirection.Input);
                values.Add("o_cur", dbType: OracleMappingType.RefCursor, direction: ParameterDirection.Output);

                data = connection.Query<Dto>("jcn_exports.get_work_notifications", values, commandType: CommandType.StoredProcedure).ToList();
            }
            Console.WriteLine($"The count is {data.Count}");
            WriteGuid(data);
        }
@gwinnem
Copy link

gwinnem commented Oct 17, 2024

Oracle does not support GUID's out of the box.
Read this: https://stackoverflow.com/questions/153815/how-should-i-store-a-guid-in-oracle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants