Hello I am getting the above error when I am running the most simple query .
Below are my files .
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="lightSpeedContexts"
type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
</configSections>
<connectionStrings>
<add name ="Dev" connectionString="Data Source=.;Initial Catalog=AdventureWorks2012;User ID=sa;Password=$sqladmin12;MultipleActiveResultSets=true"/>
</connectionStrings>
<lightSpeedContexts>
<add name="default"
connectionStringName="Dev"
dataProvider="SqlServer2005"
identityMethod="IdentityColumn"
pluralizeTableNames="False"/>
</lightSpeedContexts>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Code:
private static LightSpeedContext<LightSpeedModel1UnitOfWork> _context;
static void Main(string[] args)
{
_context = new LightSpeedContext<LightSpeedModel1UnitOfWork>("default");
_context.Logger = new Mindscape.LightSpeed.Logging.ConsoleLogger();
_context.VerboseLogging = true;
_context.IdentityMethod = IdentityMethod.IdentityColumn;
using (var vow = _context.CreateUnitOfWork())
{
Department d = new Department();
// d.DepartmentId = 18;
// d.Name = "Saled";
// d.Groupname = "Saled ";
// d.ModifiedDate = new DateTime(2010, 2, 5);
// vow.Add(d);
// vow.SaveChanges();
IList<Department> department = vow.Find<Department>(Entity.Attribute("Name")=="Engineering");
Console.WriteLine(vow.Departments.Count());
}
}
Model
/// <summary>Identifies the Name entity attribute.</summary>
public const string Namefield = "Name ";
/// <summary>Identifies the Groupname entity attribute.</summary>
public const string GroupnameField = "Groupname";
/// <summary>Identifies the ModifiedDate entity attribute.</summary>
public const string ModifiedDateField = "ModifiedDate";
/// <summary>Identifies the DepartmentId entity attribute.</summary>
public const string DepartmentIdField = "DepartmentId";
QueryGenerated
exec sp_executesql N'SELECT
HumanResources.Department .Id AS [HumanResources.Department .Id],
HumanResources.Department .DepartmentID AS [HumanResources.Department .DepartmentID],
HumanResources.Department .GroupName AS [HumanResources.Department .GroupName],
HumanResources.Department .ModifiedDate AS [HumanResources.Department .ModifiedDate],
HumanResources.Department .Name AS [HumanResources.Department .Name]
FROM
HumanResources.Department
WHERE
HumanResources.Department .Name = @p0',N'@p0 nvarchar(11)',@p0=N'Engineering'
Here you can see there is no such field Id in the Department entity but in the sql query its trying to get Id . .DepartmentId is the primary key .
How Can I fix this .
Unhandled Exception: System.Data.SqlClient.SqlException: Invalid column name 'Id '.