EF4 Code Only - Map Columns to Property Complex type
I have a table like this:
- Name
- Tree
- Iron
- Clay 开发者_Go百科
- Added
I want to map it to a model like this:
- Name
- Resources
- Tree
- Iron
- Clay
- Added
In makes sense to map it like this, when working with it in my program, but doing it that way in the databse would just make it more complex ... not would not add any useful things.
Is it possible with EF4 Code ONly?
public class Sample
{
public int Id { get; set;} // primary key required
public string Name {get;set;}
public DateTime Added{get;set;}
}
public class Resource
{
// no Id defined here
public string Tree{get;set;}
public string Iron { get;set;}
public string Clay { get;set;}
}
public class SampleDB : DbContext
{
//public DbSet<Resource> Resources { get; set; } // should not be there
public DbSet<Sample> Samples { get; set; }
}
精彩评论