i am trying to use Linq to Sql technology, but encounter some problems.
Here is my simple code.
[Table]
public class countries
{
[Column(IsPrimaryKey = true)] public int Id;
[Column] public string Country;
[Column] public int Continent;
}
class Program
{
static void Main(string[] args)
{
string connection = "SERVER=localhost; DATABASE=advworks; UID=root; PWD=root;";
DataContext dataContext = new DataContext(connect.connection);
Table<countries> table = dataContext.GetTable<countries>();
var query = from n in table
select n.Country;
foreach (var item in query)
Console.WriteLine(item);
Console.ReadKey();
}
}
I have MySql server with appropriate shema and table. The problem is that query generates this - SELECT [t0].[Country] FROM [countries] AS [t0]
but when i start the program sqlexception
is thrown because of syntax error.
i have try to input - SELECT [t0].[Country] FROM [countries] AS [t0]
in my sql directly, and it worked only after i removed square brackets.
Why linq generates this square brackets? Or there is problem with my sql server?