I have a ProductService class that defines the following methods. It doesn’t work, as I will explain further below, but it gives the compile error CS1061: ‘ProductService’ does not contain a definition for ‘GetByid’. Unless I’ve dropped the ball on method overloading, why is the public overload of GetById not seen by other code?
public IEnumerable<Product> ListActiveByCatId(Guid catId) {
return _entityContext.Products
.Include("Category")
.Where(p => p.Category.id == catId);
}
public Product GetById(string productId) {
return new Product();
}
private Product GetByid(Guid productId) {
return _entityContext.Products.First(p => p.id == productId);
}
I have the following code using a ProductService, and the two compile errors are both on this call:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
var productId = Request["productId"];
if (productId == null) {
// TODO How to get the actual parameter, not default parameter.
productDetailDataSource.SelectParameters["productId"].DefaultValue = DefaultProductId;
}
*itemTitleLabel.Text = _productService.GetByid(productId).Name;*
}
}
The exact compiler error is:
C:\SCS\Products\Details.aspx.cs(21,51):
error CS1061: ‘ProductService’ does
not contain a definition for ‘GetByid’
and no extension method ‘GetByid’
accepting a first argument of type
‘ProductService’ could be found (are
you missing a using directive or an
assembly reference?)
Line 21 is the one I attempted to emphasise, i.e. the one with asterisks around it in the above calling code.
GetByid!=GetByIdYou’ve got a casing issue.