It looks like you're trying to make EF behave like SQL, which really isn't its purpose. Many of the concepts that are fundamental to running SQL as a data provider service, such as views and stored procedures, do not have much bearing on how EF works. EF can use those things, and your program can emulate these things, but it will not specifically duplicate these things.
The virtual keyword is largely how you declare relationships.
Natural joins are easy. One to many looks like:
public class Foo
{
public int Id { get; set; }
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar
{
public int Id { get; set; }
[ForeignKey("Foo")]
public int fooId{ get; set; }
public virtual Foo Foo { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
}
EDIT:
I forgot to mention, you can invoke the property-based joins as a standard property, such as:
Foo myFoo = context.Foos.First(
List<Bar> myBar = myFoo.Bars;
M:M :
public class Foo
{
public int Id { get; set; }
public virtual ICollection<FooBar> FooBar { get; set; }
}
public class Bar
{
public int Id { get; set; }
public virtual ICollection<FooBar> FooBar { get; set; }
}
public class FooBar
{
[ForeignKey("Foo")]
public int fooId { get; set; }
[ForeignKey("Bar")]
public int barId { get; set; }
public virtual Foo Foo { get; set; }
public virtual Bar Bar { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
public DbSet<FooBar> FooBars { get; set; }
}
Now for your view question. By and large, the way that you replicate views in EF is to create ViewModels, which are POCOs that are not mapped to the database but can be constructed from either POCO classes or, if you're fancy, from the DbContext.
public class FooBarViewModel
{
public List<string> FooProp1 { get; set; }
public List<string> BarProp1 { get; set; }
public FooBarViewModel(MyContext context)
{
FooProp1 = context.Foos.Select(x => x.Prop1).toList();
BarProp1 = context.Bars.Select(x => x.Prop1).toList();
}
}
public class Foo
{
public int Id { get; set; }
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
}
Hope this helps!