When modeling a domain, is it possible to indicate that a field is fixed length?

For example, if I have a field that stores SHA1 hashes, each hash will always be exactly 20 bytes. The following property could be used to store these hashes:

[Field(Length = 20)] public byte[] Hash { get; set; }

... but the database column generated is of type varbinary(20) where I might instead prefer it to be binary(20).

There are other examples where fixed length columns are appropriate, for example a char(2) column storing ISO country codes.

asked Jan 25 '11 at 00:18

mpetito's gravatar image

mpetito
17225


One Answer:

Hello mpetito,

Unfortunately, DataObjects.Net 4 doesn't support fixed length datatypes.

answered Jan 25 '11 at 04:18

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

Is this feature planned for a future version? If not, is there a workaround? Perhaps an IModule or similar that modifies that database schema after it is built by DataObjects.Net...

(Jan 25 '11 at 10:24) mpetito mpetito's gravatar image

Could you explain, what are the benefits of fixed length datatypes and why variable length datatypes can't be used in those scenarios effectively? It is really important for the possibility of the feature.

Thanks.

(Jan 25 '11 at 10:38) Dmitri Maximov Dmitri%20Maximov's gravatar image

I think there are two main advantages. (1) Data Integrity: My specification is that each value is exactly 20 bytes. It does not make sense to put a value in of any other length. (2) Performance: Fixed length non-nullable columns require less storage space, and for records composed entirely of these columns, indexing within pages of records is optimized.

(Jan 25 '11 at 13:44) mpetito mpetito's gravatar image

I've added the request to the feature poll. Depending on the popularity, we'll implement the request sooner or later.

(Feb 24 '11 at 12:13) Dmitri Maximov Dmitri%20Maximov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×3

Asked: Jan 25 '11 at 00:18

Seen: 1,897 times

Last updated: Feb 24 '11 at 12:13

powered by OSQA