2
votes

Is there a way to generate the DBML file from entity classes instead from database tables? This would be very useful for prototyping, where one just creates a logical model and lets the auto-generated tool create the DBML file. With DBML file, one can use SqlMetal to generate Linq to SQL classes and be done with it. So, to prototype rapidly, one would:

1.Define models

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
    // etc
}

2.Run the tool (with chosen entities)

3.Get the auto-generated DBML file

4.Run the SqlMetal tool or Damiens t4 scripts to create Linq to SQL classes

5.Code against auto-generated data-context and auto-generated database (using DataContext.CreateDatabase() to create the intial DB, for instance). Some sort of DB migration would be even nicer.

Or am I weird for wanting to generate DB from objects instead of objects from DB? :)

2
Nowdays, an interesting alternative to that is by using FluentNHibernate with its auto-mapping capabilities, along with NHibernate.Linq. That way, it is very straightforward to come up with a database model and it is very easy to customize the auto-mapping as well. I hope that helps others as well.miha

2 Answers

1
votes

Doesn't exist. Currently the only method of generate a DBML for Linq to SQL is from a sql database source.

This might someday exist for the Entity Framework but current not there either.

0
votes

I actually do it in a slightly different fashion:

  1. Define an XML model of my data structures
  2. Use XSLT to generate stored procedure for create, read, upsert, etc.
  3. Use the stored procedures to create the database
  4. Work with Linq→SQL in a typical fashion, importing the stored procedures (I don't import the model because Linq→SQL doesn't know how to work with the groovy '2008 features)
  5. Work with the model