Database Reference
In-Depth Information
Inside the QueryView in Listing 6-28, we have an Entity SQL statement that contains three parts. The first part is
the select clause which instantiates an instance of the WebOrder entity with a constructor. The constructor takes the
property values in precisely the same order as they are defined on the conceptual model in Listing 6-29.
Listing 6-29. The Definition of the WebOrder Entity in the Conceptual Model
<EntityType Name="WebOrder">
<Key>
<PropertyRef Name="OrderId" />
</Key>
<Property Name="OrderId" Type="Int32" Nullable="false"
annotation:StoreGeneratedPattern="Identity" />
<Property Name="CustomerName" Type="String" Nullable="false"
MaxLength="50" Unicode="false" FixedLength="false" />
<Property Name="OrderDate" Type="DateTime" Nullable="false" />
<Property Name="IsDeleted" Type="Boolean" Nullable="false" />
<Property Name="Amount" Type="Decimal" Nullable="false"
Precision="18" Scale="2" />
</EntityType>
Notice that, in the Entity SQL in Listing 6-29 we fully qualified the conceptual namespace EFRecipesModel when
creating an instance of the WebOrder entity. However, in the from clause we also fully qualified the store container,
EFRecipesModelStoreContainer.
The final section of the Entity SQL expression includes the where clause that, of course, is the whole reason
for using a QueryView in this example. Although the where clause can be arbitrarily complex, it is subject to the
restrictions for Entity SQL in QueryView as noted above.
The code in Listing 6-30 demonstrates inserting and retrieving WebOrdersin our model.
Listing 6-30. Inserting and Retrieving WebOrder Entities
using (var context = new EF6RecipesContext())
{
var order = new WebOrder {CustomerName = "Jim Allen",
OrderDate = DateTime.Parse("5/3/2012"),
IsDeleted = false, Amount = 200};
context.WebOrders.Add(order);
order = new WebOrder { CustomerName = "John Stevens",
OrderDate = DateTime.Parse("1/1/2011"),
IsDeleted = false, Amount = 400 };
context.WebOrders.Add(order);
order = new WebOrder { CustomerName = "Russel Smith",
OrderDate = DateTime.Parse("1/3/2011"),
IsDeleted = true, Amount = 500 };
context.WebOrders.Add(order);
order = new WebOrder { CustomerName = "Mike Hammer",
OrderDate = DateTime.Parse("6/3/2013"),
IsDeleted = true, Amount = 1800 };
context.WebOrders.Add(order);
 
Search WWH ::




Custom Search