You don't have to use a dbml in order to use L2S. You can create your own classes that describe your database tables and their relationships.
Below is an extract from Microsoft's Data Developer Center
You can certainly use LINQ to SQL without DBML files. All you need are classes decorated with the [Table] and [Column] attributes. For example, if you want to query a simple Customer table, define the following class:
[Table] public class Customer
{
[Column(IsPrimaryKey=true)] public int ID;
[Column] public string Name;
}
Then you can start querying as follows:
var db = new DataContext();
var customers = db.GetTable<Customer>();
var query = customers.Where (c => c.Name.StartsWith ("a"));
You can even define assocation properties manually - the following creates classes for Customer and Purchase in a one:many relationship:
public class DemoDataContext : DataContext
{
public DemoDataContext (string cxString) : base (cxString) { }
public Table<Customer> Customers { get { return GetTable<Customer>(); } }
public Table<Purchase> Purchases { get { return GetTable<Purchase>(); } }
}
[Table] public class Customer
{
[Column(IsPrimaryKey=true)] public int ID;
[Column] public string Name;
[Association (OtherKey="CustomerID")]
public EntitySet<Purchase> Purchases = new EntitySet<Purchase>();
}
[Table] public class Purchase
{
[Column(IsPrimaryKey=true)] public int ID;
[Column] public int CustomerID;
[Column] public string Description;
[Column] public decimal Price;
[Column] public DateTime Date;
EntityRef<Customer> custRef;
[Association (Storage="custRef",ThisKey="CustomerID",IsForeignKey=true)]
public Customer Customer
{
get { return custRef.Entity; } set { custRef.Entity = value; }
}
}