Reputation: 10431
Is there a built in way to create a table if it does not exist from the DataContext Table class? Or is the only way to use raw sql statements?
Upvotes: 2
Views: 2573
Reputation: 5303
If you are talking about using the built in linq-to-sql datacontext class then you can always refresh it from the database if you create a new table and it should be picked up.
How about defining the table manually like this:
[Table(Name = "mydb.dbo.myTable")]
public class MyTable
{
[Column(Name = "Id", IsPrimaryKey = true)]
public int Id { get; set; }
[Column(Name = "ActiveDate")]
public DateTime? ActiveDate { get; set; }
}
then you can access the table like this:
var table = _seatingDataContext.Context.GetTable<MyTable>();
Then you can query it or add rows or whatever. Hope that helps.
Upvotes: 2