У меня есть таблица " Cars " с полями ModelName, Maker, Year, Price и таблица " Maker " с полем Name .Мне нужен запрос Linq to Sql, где я могу выбрать всех производителей, у которых количество моделей> n .
Я попробовал это с:
Data.ItemsSource = (from m in db.GetTable<Maker>()
where (from c in db.GetTable<Car>()
where c.Maker == m.Name
select c).Count() > 1
select m.Name);
Но безрезультатно.Как я могу это реализовать?
UPD.Код автомобиля Table
CREATE TABLE [dbo].[Car] (
[CarId] INT IDENTITY (1, 1) NOT NULL,
[ModelName] NVARCHAR (50) NOT NULL,
[Equipment] NVARCHAR (50) NULL,
[Year] INT NULL,
[Price] INT NULL,
[Cathegory] NCHAR (20) DEFAULT ('Sedan') NOT NULL,
[Maker] NCHAR (20) DEFAULT ('Toyota') NOT NULL,
PRIMARY KEY CLUSTERED ([CarId] ASC),
CONSTRAINT [FK_Car_ToCatheg] FOREIGN KEY ([Cathegory]) REFERENCES [dbo].[Catheg] ([Name]) ON DELETE CASCADE,
CONSTRAINT [FK_Car_ToMaker] FOREIGN KEY ([Maker]) REFERENCES [dbo].[Maker] ([Name]) ON DELETE CASCADE
);
Класс автомобиля
[Table(Name = "Car")]
public class Car
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int CarId { get; set; }
[Column]
public string ModelName { get; set; }
[Column]
public string Equipment { get; set; }
[Column]
public int Year { get; set; }
[Column]
public int Price { get; set; }
[Column]
public string Maker { get; set; }
[Column]
public string Cathegory { get; set; }
public Car()
{ }
public Car(string modelName, string equipment, int year, int price, string cath, string carmaker, int id = -1)
{
ModelName = modelName;
Equipment = equipment;
Year = year;
Price = price;
Maker = carmaker;
Cathegory = cath;
CarId = id;
}
public override string ToString()
{
return ModelName + " " + Equipment + " " + Year + " " + Maker + " " + Price + " " + Cathegory;
}
Код Table Maker
CREATE TABLE [dbo].[Maker] (
[Name] NCHAR (20) NOT NULL,
PRIMARY KEY CLUSTERED ([Name] ASC)
);
Класс Maker
[Table(Name = "Maker")]
public class Maker
{
[Column(IsPrimaryKey = true)]
public string Name { get; set; }
}