Suggestions: AutoGenerating fields.
Here's something I'd like to throw out...
It would be nice to specify a property to build itself if its reference is null.
That is, let's say I'm creating a Location object that has an address:
Location l = new Location();
l.Address = new Address();
Generally I'm a lazy programmer, and I'd like to be able to assume that Address is always a non-null value, like such:
Location l = new Location();
l.Address.City = "city";
And in the getter something like this:
public Address Address
{
get {
if ( _Address == null ) {_Address = new Address(); _Address.ID = Guid.NewGuid(); }
return _Address;
}
}
Along such lines, would it also be possible to autogenerate Guids? I use Guids for all my IDs, and it would be nice to save an extra line of code whenever I create an entity (why should identity columns have preferential treatment? :) ).
Anyways, those are the thoughts I see offhand... This is some REALLY wicked work! I'm excited. :)
Mike
Mike-EEE wrote: |
Here's something I'd like to throw out... It would be nice to specify a property to build itself if its reference is null. That is, let's say I'm creating a Location object that has an address: Location l = new Location(); l.Address = new Address(); Generally I'm a lazy programmer, and I'd like to be able to assume that Address is always a non-null value, like such: Location l = new Location(); l.Address.City = "city"; And in the getter something like this: public Address Address { get { if ( _Address == null ) {_Address = new Address(); _Address.ID = Guid.NewGuid(); } return _Address; } } |
|
You could of course use the constructor for this. Though you can also use a code generator to generate the classes you're mapping and use a template which generates the code you have above into the destination classes.
Along such lines, would it also be possible to autogenerate Guids? I use Guids for all my IDs, and it would be nice to save an extra line of code whenever I create an entity (why should identity columns have preferential treatment? :) ). |
|
Guid's for ID's are not a good idea in a lot of situations, unless you use the new SqlServer2005's NEWSEQUENTIALID() default value for your Guids. The problem is that Guid's trash an index, as they're not sequential. This means that if you insert a new row, it can't be appended to the data already in the table, as the PK is a clustered index (unless you define it as a non-clustered index). Auto-gen Guid support is only feasable if the o/r mapper core supports NEWSEQUENTIALID(). I know of only one who does at the moment (see sig ;))
Well, using a constructor would be my first choice. Unfortunately, a parameterless constructor is already generated in the code-gen, so providing one in the partial class generates an error...
As for NEWSEQUENTIALID... I'll give it a looksee... thanks!
Another really good post... please keep those coming! :)
Would be *very* nice to have Guid's in that auto-generating functionality. Apparently when NEO saves it to the database, it saves the GUID as empty... and there's no way of telling SQLServer2005 that Guid.Empty is actually "null." :)
Anyways... any line of code we can save is a worthy goal indeed.
Thanks!