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

Already on GitHub? Sign in to your account

Fix InsertExpression Byte Array property #344

Merged
merged 2 commits into from Dec 23, 2012

Conversation

Projects
None yet
4 participants
Contributor

spaccabit commented Dec 5, 2012

Fix migration fault, when migration have InsertExpression with a Byte
Array property.

@spaccabit spaccabit Fix InsertExpression Byte Array property
Fix migration fault, when migration have InsertExpression with a Byte
Array property.
dff52c6
Contributor

daniellee commented Dec 8, 2012

You'll have to explain this pull request a bit more. And tests are a great way to explain changes like this. And I'm curious as to why you didn't use the inbuilt BitConverter.ToString(byteArray)?

If this is what I think this is it fixes the problem where if you do

Insert.IntoTable("User")
                .Row(new { Id = CreateUser.AdministratorId, Username = "Administrator", Password = password, Salt = salt, FirstName = "Administrator", Surname = "Administrator", Email = "administrator@XXX.com" });

where "password" and "salt" are byte arrays. The following T-SQL is emitted:

INSERT INTO [dbo].[User] ([Id], [Username], [Password], [Salt], [FirstName], [Surname], [Email]) VALUES ('00000000-0000-
0000-0000-000000000001', 'Administrator', System.Byte[], System.Byte[], 'Administrator', 'Administrator', 'administrator
@XXX.com')

It doesn't know how to format byte arrays. I just ran into this. +1

Contributor

spaccabit commented Dec 9, 2012

Hi daniellee,
the behavior is same explained of worldspawn. I have not used BitConverter.ToString(byteArray) because it returns string in this format 00-7D-EC-0C-0F while the right format is 0x007DEC0C0F, and to obtain it, I have to replace the "-" character with an empty string and then append the string "0x" on head.

Contributor

daniellee commented Dec 9, 2012

Thanks for the test. I'll have a closer look at this later in the week and maybe write an integration test for this.

Is all this code not replaceable by "0x" + string.Concat(bytes.Select(b => b.ToString("X2")).ToArray())

Owner

tommarien commented Dec 10, 2012

@daniellee @spaccabit See code comment on first commit

Contributor

spaccabit commented Dec 10, 2012

I have using StringBuilder for this http://codebetter.com/raymondlewallen/2004/12/02/string-concat-versus-text-stringbuilder/ reason. I you want use LINQ

        var array = new byte[] { 0, 254, 13, 18, 125, 17 };

        var result = array.Aggregate(new StringBuilder(array.Length + 2).Append("0x")
            , (current, next) => current.AppendFormat("{0:x2}", next)
            , sb => sb.ToString());
Owner

tommarien commented Dec 10, 2012

@spaccabit thanks for the link ;)

Contributor

spaccabit commented Dec 10, 2012

;)

@tommarien tommarien merged commit 010d4ed into fluentmigrator:master Dec 23, 2012

Owner

tommarien commented Dec 23, 2012

Thanks for the fix :)

NuGet needs this patch. Happy new year!

Owner

tommarien commented Jan 1, 2013

@worldspawn I took my delorean and released it yesterday ! Cheers :)

@spaccabit spaccabit deleted the spaccabit:FixInsertExpressionByteArrayProperty branch Jul 9, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment