[LINQ] [1]についてのビデオを見ていて、問題が発生しました。このビデオでは、Mikeはデータベース名にいくつかのカスタム属性を使用していますが、それは私のためには機能しません。カスタム属性の使用
(正常に動作します)私のコード:
class MyContext : DataContext
{
public MyContext(string conStr) : base(conStr)
{
}
}
class Program
{
static void Main(string[] args)
{
MyContext ctx = new MyContext("server=.;database=AdventureWorks;Integrated Security=SSPI");
Console.WriteLine(ctx.Connection.ConnectionString);
ctx.ExecuteCommand("insert into _table (a, b) select {0}, {1}", "5", "B");
Console.WriteLine("That's it!");
Console.ReadLine();
}
}
私はそれがしたいのですがどのように
(クラスあるMyContext前に、データベース名のオブジェクトCTXと追加のカスタム属性の作成時に欠落しているデータベース・パラメータに気づきます):
[Database(Name="AdventureWorks")]
class MyContext : DataContext
{
public MyContext(string conStr) : base(conStr)
{
}
}
class Program
{
static void Main(string[] args)
{
MyContext ctx = new MyContext("server=.;Integrated Security=SSPI");
Console.WriteLine(ctx.Connection.ConnectionString);
ctx.ExecuteCommand("insert into _table (a, b) select {0}, {1}", "5", "B");
Console.WriteLine("That's it!");
Console.ReadLine();
}
}
これは、データベース名を定義しないのと同様に、「無効なオブジェクト名_table」をスローします。何か不足していますか?カスタム属性を使用するのは初めてです...