views:

73

answers:

1

We all know that Linq to SQL (and SQLmetal/exe) is really a "prototype" quality product (it's missing basic features like schema "refresh" and detection of null columns with default value).

Is there a way to automatically create my .dbml (similar to LINQ to SQL or SQLmetal) AND have it detect NOT NULL columns that have a default value?

Requirements: It needs to be just as "easy" to generate as linq-to-sql or sqlmetal.


Clarification of what I need it for:

I have many tables with DateCreated and DateModified fields as well as some bit and enum-like (int) columns with default values; all of which should be and are not null.

I will need to regenerate ("refresh") the .dbml after making changes to the database...so (re)setting the Auto-Generate (or Auto-Sync) property to True is not something I really care to be doing nearly every time I update the schema.

The following code (based on Handling Default Values With LINQ to SQL):

namespace Project.Data
{
    public partial class ProjectDataContext
    {
        partial void OnCreated()
        {
            if (this.DateCreated == null)
            {
                this.DateCreated = DateTime.UtcNow;
            }
        }
    }
}

doesn't compile (errors with ... does not contain a definition for 'DateCreated' ...). I really saw no reason it should compile...but I gave it a shot anyway. Maybe I just don't understand the context of the code from his example.

A: 
this.DateCreated ?? DateTime.UtcNow

?? means if left side is null then use right side

888
thats true. But doesn't matter really matter.
David Murdoch
yes. becus the linq object is type of System.Nullable<DateTime>
888