Question: I'm trying to check if two strings are identical as quickly as possible. Can I protect myself from hash collisions without also comparing the entire string?

I've got a cache of items that are keyed by a string. I store the hash of the string, the length of the string, and the string itself. (I'm currently using [djb2](http://www.cse.yorku.ca/~oz/hash.html) to generate the hash.)

To check if an input string is a match to an item in the cache, I compute the input's hash, and compare it to the stored hash. If that matches, I compare the length of the input (which I got as a side effect of computing the hash) to the stored length. Finally, if that matches, I do a full string comparison of the input and the stored string.

Is it necessary to do that full string comparison? For example, is there a string hashing algorithm that can mathematically guarantee that no two strings *of the same length* will generate the same hash? If not, can an algorithm guarantee that two different strings of the same length will generate different hash codes if any of the first N characters differ?

Basically, any string comparison scheme that offers O(1) performance when the strings differ but better than O(n) performance when they match would be an improvement over what I'm doing now.

Answer: 
I'm a little late to the party, but I've been having the same questions as you regarding inheritance in EF and found a pretty good summary for you to read. It's an [excerpt from Julie Lerman's book Programming Entity Framework](http://books.google.com/books?id=rtdgHbMeTBMC&lpg=PA371&ots=kUxo0EKzVD&dq=entity%20framework%20inheritance%20drawbacks&pg=PA370#v=onepage&q&f=false).

After reading it, here's my conclusions on the topic:

1) **In general, what are the pros/cons of inheritance vs extending** - The pros really depend on the table strategy you choose. See [How to choose an Inheritance Strategy - MSDN Blog](http://blogs.msdn.com/b/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx). However, they are only "pros" on the assumption that you have already decided to use inheritance at all. And that is not a decision to take lightly.

The cons are many, but the biggest is the inability to add an existing entity into the database as a derived entity. For example: I have a Student which inherits from Person. There is a Person record for John Smith. Some time later I need John Smith to be a Student. Well too bad. That's not possible. (At least not without circumventing EF with a stored procedure).

2) **In my specific example above, what would be more appropriate?** - In your example you should just add those columns (entityId, datecreated, datemodified) to tables that need them. You could use a Complex Type for datecreated and datemodified, but that wouldn't be necessary unless you're a very strict DRY guy. Even then, it might be overkill. The reason is that once you have an entity, you can never add that entity to another derived table. A Person (which is a BaseEntity) can not be added as a Student later. Also, writing LINQ queries would be far more complex than needed. Alex already showed that. 

3) **If my example is crappy for either or both, what is a good example for using inheritance and for using extending?** - Generally, if you can make your base-type abstract, inheritance *might* work for you. But you should still consider other options first. If your base type will be directly instantiated somewhere, just use composition. Inheritance gets very troublesome when it comes to actually querying and inserting records. 

In summary, just because you can do inheritance in EF does not mean you should. If you can get away with an inheritance-free design, then by all means do it.
One disadvantage of using inheritance in your model is that you won't be able to surface your model through WCF Data Services (OData) as it doesn't currently support derived entities.