1

In my project, I create Linq-to-SQL classes using SqlMetal. The problem with this is that SqlMetal doesn't appear to create a parameterless constructor. I've always gotten around this because I can always get the default connectionstring name and pass it to the constructor - however, now I am being forced to use a LinqDataSource in markup, not code, so I can't specify a constructor.

Is there any way of forcing SQLMetal to generate a parameterless constructor?
Alternatively, flipping it on its head, is there actually a way of specifying a connection string in the markup, like this:

ContextTypeName="MyNameSpace.DAL(defaultconnStr)"
mskfisher
  • 3,291
  • 4
  • 35
  • 48
higgsy
  • 1,991
  • 8
  • 30
  • 47

2 Answers2

0

I think you can create a partial class with a new parameterless constructor.

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Felipe Pessoto
  • 6,855
  • 10
  • 42
  • 73
0

SqlMetal should have generated your Entities class using a partial class. You should be able to simply add a parameterless constructor in another partial class definition:

public partial class WhateverYourEntitiesAreCalledEntities():
    this(defaultConnStr)
{
}
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536