Replies |
Try this,
public Action select()
{
var product = (from u in db.Orders
join d in db.Products on u.ProductID equals d.ProductID
select new
{
d.Name,
count = u.Orders.Count()
}).ToList();
} Regards,
Singaravel M
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Sekar.C
Posted on: 5/26/2012 9:31:30 AM
|
Level: Starter | Status: [Member] | Points: 25
|
Hi,
send your DB table structure for both tables
Regards
Sekar.c
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Srujana
Posted on: 5/28/2012 1:35:03 AM
|
Level: Starter | Status: [Member] | Points: 25
|
public class Product : BaseModel
{
[Key]
public int ProductID { get; set; }
[Required]
//[DisplayName("Group")]
[LocalizedDisplayName("FIRST_NAME", NameResourceType = typeof(Strings))]
public int ProductGroupID { get; set; }
[Required]
[DisplayName("Product")]
public int ProductNameID { get; set; }
[DisplayName("Type")]
public int? ProductTypeID { get; set; }
[Required]
[StringLength(100)]
[DisplayName("Other Name")]
public string Name { get; set; }
[Required]
[StringLength(100)]
[DisplayName("Brand")]
public string BrandName { get; set; }
[Required]
[StringLength(100)]
[DisplayName("Quality")]
public string Quality { get; set; }
[Required]
[StringLength(100)]
[DisplayName("Size - Colli")]
public string ColliSize { get; set; }
[Required]
[StringLength(100)]
[DisplayName("Colli Dimensions")]
public string ColliDimensions { get; set; }
[ScriptIgnore]
public virtual ProductGroup ProductGroup { get; set; }
[ScriptIgnore]
public virtual ProductName ProductName { get; set; }
[ScriptIgnore]
public virtual ProductType ProductType { get; set; }
[ScriptIgnore]
public virtual ColliType ColliType { get; set; }
[ScriptIgnore]
public virtual Country Country { get; set; }
[ScriptIgnore]
public virtual Currency Currency { get; set; }
[ScriptIgnore]
public virtual ICollection<PreferredLocation> PreferredLocations { get; set; }
[ScriptIgnore]
public virtual ICollection<Order> Orders { get; set; }
}
}
public class ProductName : BaseModel
{
[Key]
public int ProductNameID { get; set; }
[DisplayName("Product")]
[StringLength(50)]
public string Name { get; set; }
[Required]
public int ProductGroupID { get; set; }
[ScriptIgnore]
public virtual ProductGroup ProductGroup { get; set; }
[ScriptIgnore]
public virtual ICollection<Product> Products { get; set; }
[ScriptIgnore]
public virtual ICollection<ProductType> ProductTypes { get; set; }
}
public class Order : BaseModel
{
[Key]
public int OrderID { get; set; }
[Required]
[DisplayName("Colli Count")]
public int ColliCount { get; set; }
[Required]
[DisplayName("Order Available?")]
public bool OrderAvailable { get; set; }
[Required]
[DisplayName("Order Shipped")]
public bool OrderShipped { get; set; }
[Required]
[DisplayName("Order Completed")]
public bool OrderCompleted { get; set; }
[DisplayName("Order Cancelled")]
public bool OrderCancelled { get; set; }
[Required]
[ForeignKey("Buyer")]
public int BuyerID { get; set; }
[Required]
[ForeignKey("Seller")]
public int SellerID { get; set; }
[Required]
public int ProductID { get; set; }
//public int OfferID { get; set; }
[Required]
public int PreferredLocationID { get; set; }
public float? Latitude { get; set; }
public float? Longitude { get; set; }
[ScriptIgnore]
public virtual User Buyer { get; set; }
[ScriptIgnore]
public virtual User Seller { get; set; }
[ScriptIgnore]
public virtual Product Product { get; set; }
public virtual PreferredLocation PreferredLocation { get; set; }
}
These are three model classes,
I need to retrieve no.of orders for each product.
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Sabarimahesh
Posted on: 5/31/2012 9:52:48 AM
|
Level: Bronze | Status: [Member] | Points: 25
|
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Sabarimahesh
Posted on: 5/31/2012 9:53:18 AM
|
Level: Bronze | Status: [Member] | Points: 25
|
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Srujana, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|