I've started out using the CodeFirst approach in the entity framework.
When running my code I am unable to perform any operation on the DbSets within the DbContext - ProductsDb
I have checked the connection string and I think it is correct but attempting to perform operation results in the error
Value cannot be null, parameter source.
Here is the ProductsDb class
public class ProductsDb : DbContext
{
public ProductsDb(string connectionString) : base(connectionString)
{
}
public ProductsDb()
{
}
public DbSet<AProduct> AProducts;
public DbSet<BProduct> BProducts;
public DbSet<CProduct> CProducts;
public DbSet<DProduct> DProducts;
}
The connection string is defined in the app.config as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ProductsDb" providerName="System.Data.SqlClient"
connectionString="Data Source=MyPC\DEV;Initial Catalog=Test;User ID=sa;
Password=pass;" />
</connectionStrings>
</configuration>
The code that throws the error is:
GetAProduct(string id)
{
AProduct aProduct = null;
using (ProductsDb productsDb = new ProductsDb())
{
aProduct = (from a in productsDb.AProducts
where a.Id== id
select a).FirstOrDefault();
}
return aProduct;
}
All of the product classes are plain old C# classes.
Any help would be really appreciated, I'm starting to pull my hair out. Never have any problems when writing Sql queries.
UPDATE: Copy Paste error the GetAProduct method has been altered.
productsDb