I'm using a auto created Linq to SQL Classes dbml and I have created the model class by hand. It should select all Schemas from a SQL Server, which is working when there are more than one Schema in the Database, but when there is only a single result I get an empty collection as result.
I have also exact the same models for Tables and Views which are showing me the same behavior.
What am I missing in order to get also a single result?
Code:
var schemaQuery = "SELECT Distinct
SCHEMA_NAME(schema_id) as Name,
schema_id as Id
from sys.tables
Order by Name"
var context = new DbDataContext();
var schemas = context.ExecuteQuery<Schema>(schemaQuery);
Model class:
public class Schema
{
private int _id;
private string _name;
[ColumnAttribute(Storage = "_id", DbType = "Int NOT NULL")]
public int Id
{
get
{
return _id;
}
set
{
if (_id != value)
{
_id = value;
}
}
}
[ColumnAttribute(Storage = "_name", DbType = "NVarChar(MAX)")]
public string Name
{
get
{
return _name;
}
set
{
if (_name != value)
{
_name = value;
}
}
}
}
Results: Database with dbo and System schemas
Databse with only dbo schema