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

BitArray Bitwise operators #2793

Open
Magehernan opened this issue Jun 17, 2023 · 4 comments
Open

BitArray Bitwise operators #2793

Magehernan opened this issue Jun 17, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@Magehernan
Copy link

Hi, i am trying to use bit(256) type on postgre because it has the & and | operators but in c# using BitArray and linq i can't make the translation work, i try with the BitArray.And but it cannot be translated and it don't has & operator but it is in postgre.

I am looking at the source and trying with expressions but i can't make it work.

I was trying to make a custom translator but i can't add it, any suggestions on how approch this need?

Thanks!

@roji roji marked this as a duplicate of dotnet/efcore#18795 Jun 18, 2023
@roji
Copy link
Member

roji commented Jun 18, 2023

It should be pretty easy to translate e.g BitArray.And to the PostgreSQL & operator, but there's a slight mismatch - the .NET And mutates the BitArray on which it's invoked (and also returns that same instance); in PG it obviously wouldn't do that. I'll need to think a bit more if it makes sense to do that translation given that mismatch.

In any case, in the meantime you can use SQL querying where you need these PG operators.

@roji roji added this to the Backlog milestone Jun 18, 2023
@roji roji added the enhancement New feature or request label Jun 18, 2023
@Magehernan
Copy link
Author

Thanks, i understand, i am new on looking at translations so i wasn't sure if it was the best way to do it.
When you say sql querying you refer to use from the entity the fromSql metod?

I start using BitArray but the type i need is BigInteger so when i use it map to numeric and because that postgre don't have the & operator on it, so the ideal think for me is BigInteger map to Bit(256) and because BigInteger in c# has the & maybe instead a translation i need a custom mapping? that could be a good way implement my requirement?

Thank a lot!

@Magehernan
Copy link
Author

So in my specific case i think i solve it, because of that my type really is a BigInteger and it has the & operator i can write a linq valid and then added OnModelCreating in my entity to my property,

b.Property(t => t.Gene).HasColumnType("BIT(256)").HasConversion(v => v.ToBitArray(), v => v.ToBigInteger());

where t.Gene is BigInteger? and the column in the database is Bit(256) nullable and i created 2 extensions methods to convert to one another.

Thanks for the help!

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
@roji roji reopened this Jun 19, 2023
@roji
Copy link
Member

roji commented Jun 19, 2023

Reopening to keep this in the backlog.

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

No branches or pull requests

2 participants