Entity Auto-Generated Table Identifiers

Using the Entity Framework often records requests such as

var orders = from o in context.Orders.Include("Customer")
             where o.OrderDate.HasValue && o.OrderDate.Value.Year == 1997
             orderby o.Freight
             select o;

What my stomach really does is the "Customer"string argument . I find it hard to believe that EF does not generate table names as constants somewhere. Does anyone know a better approach than using a string? for the Includefetch option ?

+5
source share
4 answers

EF 4.1 Include IQueryable, ObjectQuery DbQuery. EntityFramework.dll(EF 4.1), System.Data.Entity -

// get Orders with related Customers
var orders = from o in context.Orders.Include(o => o.Customer) ...

Edit:

EF 4.1, . , .

+6

IMO GetType , .edmx, ,

 context.Orders.Include(CustomerEntity.GetType.Name or full name )
+1

Include(context.Customers.EntitySet.Name)

?

+1

You can create a text template that allows you to generate code in addition to the default EF code. You can do this by right-clicking and clicking on โ€œAdd Code Generation Itemโ€.

In this text template, you can create your constants as needed in "CustomerProperties" and create a constant name for each navigation property.

http://msdn.microsoft.com/en-us/data/gg558520

+1
source

All Articles