Skip to content

Detect and upgrade from macaddr to macaddr8 #428

Description

@austindrenski

Background

While working on #407, I'm finding it difficult to send PhysicalAddress parameters to PostgreSQL functions that expect a macaddr8 because the default mapping is for macaddr.

Based on the docs, it looks like these types are intended to interoperate smoothly:

This type can accept both 6 and 8 byte length MAC addresses and stores them in 8 byte length format. MAC addresses given in 6 byte format will be stored in 8 byte length format with the 4th and 5th bytes set to FF and FE, respectively.

This would normally be handled by setting a different CLR type as the default mapping for macaddr8. However, since PhysicalAddress can accommodate the 8-byte width, I would like to avoid introducing another provider-specific type just for the new width.

Question

Is it be possible for MacaddrHandler to forward to Macaddr8Handler on write operations when a PhysicalAddress parameter has a byte length of 8?

Example

publicclassNetTestEntity{// This is the default mapping.[Column(TypeName="macaddr")]publicPhysicalAddressMacaddr{get;set;}[Column(TypeName="macaddr8")]publicPhysicalAddressMacaddr8{get;set;}}// Passes[Fact]publicvoidPhysicalAddress_macaddr_LessThan_macaddr(){using(NetContextcontext=Fixture.CreateContext()){PhysicalAddressmacaddr=newPhysicalAddress(newbyte[6]);NetTestEntity[]_=context.NetTestEntities.Where(x =>EF.Functions.LessThan(x.Macaddr,macaddr)).ToArray();AssertContainsSql("WHERE (x.\"Macaddr\" < @__macaddr_1) = TRUE");}}// Passes[Fact]publicvoidPhysicalAddress_macaddr8_LessThan_macaddr8(){using(NetContextcontext=Fixture.CreateContext()){NetTestEntity[]_=context.NetTestEntities.Where(x =>EF.Functions.LessThan(x.Macaddr8,x.Macaddr8)).ToArray();AssertContainsSql("WHERE (x.\"Macaddr8\" < x.\"Macaddr8\") = TRUE");}}// Fails://// System.FormatException : MAC addresses must have length 6 in PostgreSQL// at Npgsql.TypeHandlers// .NetworkHandlers// .MacaddrHandler// .ValidateAndGetLength(PhysicalAddress value, NpgsqlParameter parameter)[Fact]publicvoidPhysicalAddress_macaddr8_LessThan_macaddr8_parameter(){using(NetContextcontext=Fixture.CreateContext()){PhysicalAddressmacaddr8=newPhysicalAddress(newbyte[8]);NetTestEntity[]_=context.NetTestEntities.Where(x =>EF.Functions.LessThan(x.Macaddr8,macaddr8)).ToArray();AssertContainsSql("WHERE (x.\"Macaddr8\" < @__macaddr8_1) = TRUE");}}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions