views:

458

answers:

1

I will like to know that is there a way to exclude some fields from the database? For eg:

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string FatherName { get; set; }

    public bool IsMale { get; set; }
    public bool IsMarried { get; set; }

    public string AddressAs { get; set; }
}

How can I exclude the AddressAs field from the database?

+6  A: 

In the current version the only way to exclude a property is to explicitly map all the other columns:

builder.Entity<Employee>().MapSingleType(e => new {
  e.Id,
  e.Name,
  e.FatherName,
  e.IsMale,
  e.IsMarried
});

Because AddressAs is not referenced it isn't part of the Entity / Database.

The EF team is considering adding something like this:

builder.Entity<Employee>().Exclude(e => e.AddressAs);

I suggest you tell leave a comment on the EFDesign blog, requesting this feature :)

Hope this helps

Alex

Alex James
I realized that the only way to do it as of today is the way you mentioned. I posted it on EFDesign blog a long back: http://blogs.msdn.com/efdesign/archive/2009/10/12/code-only-further-enhancements.aspx
Yogesh