I created a new class library project in Visual Studio 2012, to define data classes in order to enable new database creation using Entity Framework code first. So I created 3 classes:
Product as next:
namespace MyClassLibrary
{
public class Product
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
}
}
Category as next:
using System.Collections.Generic;
namespace MyClassLibrary
{
public class Department
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
}
and ICategoryDataSource as next:
using System.Linq;
namespace MyClassLibrary
{
public class ICategoryDataSource
{
IQueryable<Product> Products { get; }
IQueryable<Category> Categories { get; }
}
}
In the last class, I get the next error message: ‘MyClassLibrary.ICategoryDataSource.Products.get’ must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
I do not need a setter here, please advise how can I avoid using set accessors.
By the name in the last code section, I assume you want
ICategoryDataSourceto be an interface, not a class: