using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using DelegateDecompiler;
public class Aps : DbContext
public Aps() : base(FiddleHelper.GetConnectionStringSqlServer())
protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<Customer>()
.HasRequired<Application>(c => c.Application)
.WithMany(a => a.Customers)
.HasForeignKey<int>(c => c.ApplicationId)
.WillCascadeOnDelete(false);
public DbSet<Application> Applications { get; set; }
public DbSet<Customer> Customers { get; set; }
public int ApplicationId { get; set; }
public string Name { get; set; }
get { return "STB" + " " + Name; }
public ICollection<Customer> Customers { get; set; }
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
get { return FirstName + " " + LastName; }
public int ApplicationId { get; set; }
public Application Application { get; set; }
public static void Main()
using (var db = new Aps())
List<Application> applications = new List<Application>
Name = "Aplikacija Visa karticka",
Customers = new List<Customer>
new Customer(){FirstName = "Ratko", LastName = "Projkovski"}
Name = "Aplikacija potrosuvacki",
Customers = new List<Customer>
new Customer(){FirstName = "Aleksandar", LastName = "Lozanovski"},
new Customer(){FirstName = "Tose", LastName = "Janev"}
Name = "Aplikacija Stamben",
Customers = new List<Customer>
new Customer(){FirstName = null, LastName = null}
db.Applications.AddRange(applications);
var query = db.Applications.Include(x => x.Customers).Where(x => x.Customers.Any(y => y.Name.Contains("ose"))).Decompile();
Console.WriteLine(query);
FiddleHelper.WriteTable(query);