I am facing issues in below piece of code. Everything looks fine but still I get below Error:
'MetalItems' does not contain a definition for 'metals' and no extension method 'metals' accepting a first argument of type 'MetalItems' could be found (are you missing a using directive or an assembly reference?) E:\VS2010\Jewellery\SilverSpoon\SilverSpoon\API\models\MetalItems.cs 38 52 SilverSpoon
CODE
class MetalItems
{
public int ID { get; set; }
public int metal_id { get; set; }
public string item_name { get; set; }
public Metals metals {get; set;}
public IEnumerable<MetalItems> findAllJoin<MetalItems>()
{
IEnumerable<MetalItems> data = null;
using (var sqlConnection = Database.getConnection())
{
data = sqlConnection
.Query<MetalItems, Metals, MetalItems>(
@"SELECT * FROM metal_items mi JOIN metals m ON mi.metal_id = m.metal_id ORDER BY mi.metal_id",
(mi, m) =>
{
mi.metals = m;
return mi;
},
splitOn: "metal_id");
}
return data;
}
}
class Metals
{
public int metal_id { get; set; }
public string metal_name { get; set; }
public decimal rate_per_gram { get; set; }
public decimal making_charges { get; set; }
}
ERROR LINE is display in below snapshot;
Generally I'm not awfully fund of classes with data operations in them, would prefer to separate this logic to it's own data layer but if this is what you want...
Just remove the "generic"? part of your findAllJoin method and it should work just fine
public IEnumerable<MetalItems> findAllJoin()
{
IEnumerable<MetalItems> data = null;
using (var sqlConnection = Database.getConnection())
{
data = sqlConnection
.Query<MetalItems, Metals, MetalItems>(
@"SELECT * FROM metal_items mi JOIN metals m ON mi.metal_id = m.metal_id ORDER BY mi.metal_id",
(mi, m) =>
{
mi.metals = m;
return mi;
},
splitOn: "metal_id");
}
return data;
}