Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace AdvancedPatternsModel
{
using System.Data.Entity;
public class AdvancedPatternsEmployeeContext : DbContext
{
public AdvancedPatternsEmployeeContext()
: base("AdvancedPatternsDatabase")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
AdvancedPatternsMasterContext.SetupModel(modelBuilder);
base.OnModelCreating(modelBuilder);
}
public DbSet<Employee> AllEmployees { get; set; }
public DbSet<PastEmployee> PastEmployees { get; set; }
public DbSet<CurrentEmployee> CurrentEmployees { get; set; }
}
}

View File

@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Reflection;
public abstract class CachingCollectionInitializer
{
private static readonly ConcurrentDictionary<Type, IList<Tuple<string, Func<DbCollectionEntry, object>>>> _factories
= new ConcurrentDictionary<Type, IList<Tuple<string, Func<DbCollectionEntry, object>>>>();
private static readonly MethodInfo _factoryMethodInfo
= typeof(CachingCollectionInitializer).GetMethod("CreateCollection");
public virtual Type TryGetElementType(PropertyInfo collectionProperty)
{
// We can only replace properties that are declared as ICollection<T> and have a setter.
var propertyType = collectionProperty.PropertyType;
if (propertyType.IsGenericType &&
propertyType.GetGenericTypeDefinition() == typeof(ICollection<>)
&&
collectionProperty.GetSetMethod() != null)
{
return propertyType.GetGenericArguments().Single();
}
return null;
}
public virtual void InitializeCollections(DbContext context, object entity)
{
var factories = _factories.GetOrAdd(
entity.GetType(), t =>
{
var list = new List<Tuple<string, Func<DbCollectionEntry, object>>>();
foreach (var property in t.GetProperties())
{
var collectionEntry = context.Entry(entity).Member(property.Name) as DbCollectionEntry;
if (collectionEntry != null)
{
var elementType = TryGetElementType(property);
if (elementType != null)
{
list.Add(Tuple.Create(property.Name, CreateCollectionFactory(elementType)));
}
}
}
return list;
});
foreach (var factory in factories)
{
var collectionEntry = context.Entry(entity).Collection(factory.Item1);
collectionEntry.CurrentValue = factory.Item2(collectionEntry);
}
}
public virtual Func<DbCollectionEntry, object> CreateCollectionFactory(Type elementType)
{
return (Func<DbCollectionEntry, object>)Delegate.CreateDelegate(
typeof(Func<DbCollectionEntry, object>), this,
_factoryMethodInfo.MakeGenericMethod(elementType));
}
public abstract object CreateCollection<TElement>(DbCollectionEntry collectionEntry);
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
using System.Collections.Generic;
public static class CollectionExtensions
{
public static bool IsLoaded<T>(this ICollection<T> collection)
{
var asHasIsLoaded = collection as IHasIsLoaded;
return asHasIsLoaded != null ? asHasIsLoaded.IsLoaded : true;
}
public static void SetLoaded<T>(this ICollection<T> collection, bool isLoaded)
{
var asHasIsLoaded = collection as IHasIsLoaded;
if (asHasIsLoaded != null)
{
asHasIsLoaded.IsLoaded = isLoaded;
}
}
}
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
public interface IHasIsLoaded
{
bool IsLoaded { get; set; }
}
}

View File

@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public class LazyBlogContext : DbContext
{
public LazyBlogContext()
{
Database.SetInitializer(new LazyBlogsContextInitializer());
Configuration.LazyLoadingEnabled = false;
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized +=
(s, e) => new QueryableCollectionInitializer().InitializeCollections(this, e.Entity);
}
public DbSet<LazyPost> Posts { get; set; }
public DbSet<LazyComment> Comments { get; set; }
}
public class LazyBlogsContextInitializer : DropCreateDatabaseIfModelChanges<LazyBlogContext>
{
protected override void Seed(LazyBlogContext context)
{
context.Posts.Add(
new LazyPost
{
Id = 1,
Title = "Lazy Unicorns",
Comments = new List<LazyComment>
{
new LazyComment
{
Content = "Are enums supported?"
},
new LazyComment
{
Content = "My unicorns are so lazy they fell asleep."
},
new LazyComment
{
Content = "Is a unicorn without a horn just a horse?"
},
}
});
context.Posts.Add(
new LazyPost
{
Id = 2,
Title = "Sleepy Horses",
Comments = new List<LazyComment>
{
new LazyComment
{
Content = "Are enums supported?"
},
}
});
}
}
public class LazyComment
{
public int Id { get; set; }
public string Content { get; set; }
public LazyPost Post { get; set; }
}
public class LazyPost
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public ICollection<LazyComment> Comments { get; set; }
}
}

View File

@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
public class QueryableCollection<T> : ICollection<T>, IQueryable<T>, IHasIsLoaded
{
private readonly ICollection<T> _collection;
private readonly IQueryable<T> _query;
public QueryableCollection(ICollection<T> collection, IQueryable<T> query)
{
_collection = collection ?? new HashSet<T>();
_query = query;
}
public IQueryable<T> Query
{
get { return _query; }
}
public bool IsLoaded { get; set; }
public void Add(T item)
{
_collection.Add(item);
}
public void Clear()
{
LazyLoad();
_collection.Clear();
}
public bool Contains(T item)
{
LazyLoad();
return _collection.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
LazyLoad();
_collection.CopyTo(array, arrayIndex);
}
public int Count
{
get { return IsLoaded ? _collection.Count : _query.Count(); }
}
public bool IsReadOnly
{
get { return _collection.IsReadOnly; }
}
public bool Remove(T item)
{
LazyLoad();
return _collection.Remove(item);
}
public IEnumerator<T> GetEnumerator()
{
LazyLoad();
return _collection.GetEnumerator();
}
public bool TestLoadInEnumerator { get; set; }
IEnumerator IEnumerable.GetEnumerator()
{
// Calling lazy load here would previously cause EF to throw--see Dev11 205813
// It no longer throws, but we still can't call Load here because DetectChanges uses
// this method to determine if there are any entities in the collection, and so calling
// load here will cause DetectChanges to lazily load the collection.
// It's generally okay not to call load here because the normal case of enumerating
// the collection is through the generic enumerator
if (TestLoadInEnumerator)
{
LazyLoad();
}
return ((IEnumerable)_collection).GetEnumerator();
}
private void LazyLoad()
{
if (!IsLoaded)
{
IsLoaded = true;
_query.Load();
}
}
Expression IQueryable.Expression
{
get { return _query.Expression; }
}
Type IQueryable.ElementType
{
get { return _query.ElementType; }
}
IQueryProvider IQueryable.Provider
{
get { return _query.Provider; }
}
}
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace LazyUnicorns
{
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
public class QueryableCollectionInitializer : CachingCollectionInitializer
{
public override object CreateCollection<TElement>(DbCollectionEntry collectionEntry)
{
return new QueryableCollection<TElement>(
(ICollection<TElement>)collectionEntry.CurrentValue,
collectionEntry.Query().Cast<TElement>());
}
}
}

View File

@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace ProductivityApiTests
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
public class InvalidProduct
{
public float? Id { get; set; }
public string Name { get; set; }
}
public class InvalidDerivedProductDependent : InvalidProduct
{
public string SalePrice { get; set; }
public Guid Quantity { get; set; }
public Guid? PrincipalId { get; set; }
[ForeignKey("PrincipalId")]
public InvalidPrincipal PrincipalNavigation { get; set; }
}
public class InvalidPrincipal
{
public Guid Id { get; set; }
public byte[] Description { get; set; }
public ICollection<InvalidDerivedProductDependent> DerivedProductDependentNavigation { get; set; }
}
/// <summary>
/// Validation of this model will fail. Currently this happens after the model has been
/// built when it is passed to WriteEdmx or Compile. In the future the pipeline may be fixed
/// such that it fails when Build is called.
/// </summary>
public class InvalidMappingContext : DbContext
{
public InvalidMappingContext()
{
Database.SetInitializer<InvalidMappingContext>(null);
}
public DbSet<InvalidProduct> Products { get; set; }
public DbSet<InvalidPrincipal> Principals { get; set; }
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Entity<InvalidProduct>();
builder.Entity<InvalidPrincipal>();
builder.Entity<InvalidProduct>()
.Map(mapping => mapping.Requires("PrincipalId").HasValue(null))
.Map<InvalidDerivedProductDependent>(mapping => mapping.Requires(e => e.PrincipalId).HasValue())
.ToTable("Product");
builder.Entity<InvalidDerivedProductDependent>().HasOptional(e => e.PrincipalNavigation).WithMany(
e => e.DerivedProductDependentNavigation);
builder.Entity<InvalidPrincipal>().HasMany(e => e.DerivedProductDependentNavigation).WithOptional(e => e.PrincipalNavigation);
builder.Entity<InvalidProduct>().Property(p => p.Id).HasColumnType("real");
builder.Entity<InvalidProduct>().Property(p => p.Name).IsRequired().HasColumnType("xml");
builder.Entity<InvalidDerivedProductDependent>().Property(p => p.SalePrice).IsRequired().HasColumnType("char").HasMaxLength(20).
IsFixedLength();
builder.Entity<InvalidDerivedProductDependent>().Property(p => p.Quantity).HasColumnType("uniqueidentifier");
builder.Entity<InvalidDerivedProductDependent>().Property(p => p.PrincipalId).HasColumnType("uniqueidentifier");
builder.Entity<InvalidPrincipal>().Property(p => p.Id).HasColumnType("uniqueidentifier");
builder.Entity<InvalidPrincipal>().Property(p => p.Description).HasColumnType("binary").HasMaxLength(10).IsFixedLength();
}
}
}

View File

@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace InvalidTypeModel
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace InvalidTypeModel
{
using System.Data.Entity;
public class PersonContext : DbContext
{
public DbSet<Person> People { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
/// <summary>
/// A base type used for all entities used for DbQuery LINQ tests.
/// </summary>
public class BaseTypeForLinq
{
/// <summary>
/// The primary key for all entities used in LINQ tests.
/// </summary>
public int Id { get; set; }
/// <summary>
/// This method allows to entities to be tested for equality in a non-standard way.
/// It is non-standard because it doesn't need to be as robust as a general purpose
/// Equals implementation, and because it should never be used by framework code itself
/// since this could risk causing framework behavior to change.
/// </summary>
/// <param name="other"> The entity to compare. </param>
/// <returns> True if they represent the same entity; false otherwise. </returns>
public virtual bool EntityEquals(BaseTypeForLinq other)
{
return Id == other.Id;
}
/// <summary>
/// A hash code that works in conjunction with the EntityEquals method.
/// </summary>
public virtual int EntityHashCode
{
get { return Id; }
}
}
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System.Collections.Generic;
/// <summary>
/// Compares two BaseTypeForLinq objects.
/// </summary>
public class BaseTypeForLinqComparer : IEqualityComparer<BaseTypeForLinq>
{
public bool Equals(BaseTypeForLinq left, BaseTypeForLinq right)
{
return (left == null && right == null) ||
(left.GetType() == right.GetType() && left.EntityEquals(right));
}
public int GetHashCode(BaseTypeForLinq entity)
{
return entity.EntityHashCode;
}
}
}

View File

@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
public class CustomerForLinq : BaseTypeForLinq
{
public string Region { get; set; }
public string CompanyName { get; set; }
public ICollection<OrderForLinq> Orders { get; set; }
public override bool EntityEquals(BaseTypeForLinq other)
{
Debug.Assert(other is CustomerForLinq, "Expected other side to already have been checked to be the correct type.");
var otherCustomer = (CustomerForLinq)other;
var customersEqual = Orders == null
? otherCustomer.Orders == null
: Orders.SequenceEqual(otherCustomer.Orders, new BaseTypeForLinqComparer());
return base.EntityEquals(other) && customersEqual;
}
public override int EntityHashCode
{
get
{
var hash = base.EntityHashCode;
if (Orders != null)
{
foreach (var item in Orders)
{
hash = 37 * hash + item.EntityHashCode;
}
}
return hash;
}
}
public override string ToString()
{
var builder = new StringBuilder();
builder.AppendLine(
String.Format(CultureInfo.InvariantCulture, "ID: {0}, Region: {1}, CompanyName: {2}", Id, Region, CompanyName));
if (Orders != null)
{
foreach (var order in Orders)
{
builder.Append(" ").AppendLine(order.ToString());
}
}
return builder.ToString();
}
}
}

View File

@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
public class FeaturedProductForLinq : ProductForLinq
{
}
}

View File

@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System;
using System.Globalization;
public class NumberForLinq : BaseTypeForLinq
{
public NumberForLinq()
{
}
public NumberForLinq(int value, string name)
{
Value = value;
Name = name;
}
public int Value { get; set; }
public string Name { get; set; }
public override string ToString()
{
return String.Format(CultureInfo.InvariantCulture, "ID: {0}, Value: {1}, Name: {2}", Id, Value, Name);
}
}
}

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System;
using System.Diagnostics;
using System.Globalization;
public class OrderForLinq : BaseTypeForLinq
{
public decimal Total { get; set; }
public DateTime OrderDate { get; set; }
public CustomerForLinq Customer { get; set; }
public override bool EntityEquals(BaseTypeForLinq other)
{
Debug.Assert(other is OrderForLinq, "Expected other side to already have been checked to be the correct type.");
var otherOrder = (OrderForLinq)other;
var customersEqual = Customer == null ? otherOrder.Customer == null : Customer.Id == otherOrder.Customer.Id;
return base.EntityEquals(other) && customersEqual;
}
public override int EntityHashCode
{
get { return Customer == null ? Id : (37 * Id + Customer.Id); }
}
public override string ToString()
{
return String.Format(CultureInfo.InvariantCulture, "ID: {0}, Total: {1}, OrderDate: {2}", Id, Total, OrderDate);
}
}
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System;
using System.Globalization;
public class ProductForLinq : BaseTypeForLinq
{
public string ProductName { get; set; }
public string Category { get; set; }
public decimal UnitPrice { get; set; }
public int UnitsInStock { get; set; }
public override string ToString()
{
return String.Format(
CultureInfo.InvariantCulture, "ID: {0}, Name: {1}, Category: {2}, UnitePrice: {3}, UnitsInStock: {4}", Id, ProductName,
Category, UnitPrice, UnitsInStock);
}
}
}

View File

@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System.Data.Entity;
using System.Linq;
/// <summary>
/// A simple context for use in DbQuery LINQ testing.
/// </summary>
public class SimpleModelForLinq : DbContext
{
static SimpleModelForLinq()
{
Database.SetInitializer(new SimpleModelForLinqInitializer());
}
public DbSet<NumberForLinq> Numbers { get; set; }
public DbSet<ProductForLinq> Products { get; set; }
public DbSet<CustomerForLinq> Customers { get; set; }
public DbSet<OrderForLinq> Orders { get; set; }
public IQueryable<NumberForLinq> NumbersGreaterThanTen()
{
return Numbers.Where(n => n.Value > 10);
}
public IQueryable<ProductForLinq> ProductsStartingWithP
{
get { return Products.Where(p => p.ProductName.StartsWith("P")); }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<NumberForLinq>().HasKey(e => e.Id);
modelBuilder.Entity<ProductForLinq>().HasKey(e => e.Id);
modelBuilder.Entity<CustomerForLinq>().HasKey(e => e.Id);
modelBuilder.Entity<OrderForLinq>().HasKey(e => e.Id);
}
}
}

View File

@@ -0,0 +1,250 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace SimpleModel
{
using System;
using System.Collections.Generic;
using System.Data.Entity;
public class SimpleModelForLinqInitializer : DropCreateDatabaseIfModelChanges<SimpleModelForLinq>
{
protected override void Seed(SimpleModelForLinq context)
{
new List<NumberForLinq>
{
new NumberForLinq(5, "Five"),
new NumberForLinq(4, "Four"),
new NumberForLinq(1, "One"),
new NumberForLinq(3, "Three"),
new NumberForLinq(9, "Nine"),
new NumberForLinq(8, "Eight"),
new NumberForLinq(6, "Six"),
new NumberForLinq(7, "Seven"),
new NumberForLinq(2, "Two"),
new NumberForLinq(0, "Zero"),
}.ForEach(i => context.Numbers.Add(i));
new List<ProductForLinq>
{
new ProductForLinq
{
ProductName = "Chai",
Category = "Beverages",
UnitPrice = 18.0000M,
UnitsInStock = 39
},
new ProductForLinq
{
ProductName = "Chang",
Category = "Beverages",
UnitPrice = 19.0000M,
UnitsInStock = 17
},
new ProductForLinq
{
ProductName = "Aniseed Syrup",
Category = "Condiments",
UnitPrice = 10.0000M,
UnitsInStock = 13
},
new ProductForLinq
{
ProductName = "Chef Anton's Cajun Seasoning",
Category = "Condiments",
UnitPrice = 22.0000M,
UnitsInStock = 53
},
new ProductForLinq
{
ProductName = "Chef Anton's Gumbo Mix",
Category = "Condiments",
UnitPrice = 21.3500M,
UnitsInStock = 0
},
new ProductForLinq
{
ProductName = "Grandma's Boysenberry Spread",
Category = "Condiments",
UnitPrice = 25.0000M,
UnitsInStock = 120
},
new ProductForLinq
{
ProductName = "Uncle Bob's Organic Dried Pears",
Category = "Produce",
UnitPrice = 30.0000M,
UnitsInStock = 15
},
new FeaturedProductForLinq
{
ProductName = "Northwoods Cranberry Sauce",
Category = "Condiments",
UnitPrice = 40.0000M,
UnitsInStock = 6
},
new ProductForLinq
{
ProductName = "Mishi Kobe Niku",
Category = "Meat/Poultry",
UnitPrice = 97.0000M,
UnitsInStock = 29
},
new ProductForLinq
{
ProductName = "Ikura",
Category = "Seafood",
UnitPrice = 31.0000M,
UnitsInStock = 31
},
new ProductForLinq
{
ProductName = "Queso Cabrales",
Category = "Dairy Products",
UnitPrice = 21.0000M,
UnitsInStock = 22
},
new FeaturedProductForLinq
{
ProductName = "Queso Manchego La Pastora",
Category = "Dairy Products",
UnitPrice = 38.0000M,
UnitsInStock = 86
},
new ProductForLinq
{
ProductName = "Konbu",
Category = "Seafood",
UnitPrice = 6.0000M,
UnitsInStock = 24
},
new ProductForLinq
{
ProductName = "Tofu",
Category = "Produce",
UnitPrice = 23.2500M,
UnitsInStock = 35
},
new ProductForLinq
{
ProductName = "Genen Shouyu",
Category = "Condiments",
UnitPrice = 15.5000M,
UnitsInStock = 39
},
new ProductForLinq
{
ProductName = "Pavlova",
Category = "Confections",
UnitPrice = 17.4500M,
UnitsInStock = 29
},
new FeaturedProductForLinq
{
ProductName = "Alice Mutton",
Category = "Meat/Poultry",
UnitPrice = 39.0000M,
UnitsInStock = 0
},
new FeaturedProductForLinq
{
ProductName = "Carnarvon Tigers",
Category = "Seafood",
UnitPrice = 62.5000M,
UnitsInStock = 42
},
new ProductForLinq
{
ProductName = "Teatime Chocolate Biscuits",
Category = "Confections",
UnitPrice = 9.2000M,
UnitsInStock = 25
},
new ProductForLinq
{
ProductName = "Sir Rodney's Marmalade",
Category = "Confections",
UnitPrice = 81.0000M,
UnitsInStock = 40
},
new ProductForLinq
{
ProductName = "Sir Rodney's Scones",
Category = "Confections",
UnitPrice = 10.0000M,
UnitsInStock = 3
},
}.ForEach(i => context.Products.Add(i));
var customers = new List<CustomerForLinq>
{
new CustomerForLinq
{
Region = "WA",
CompanyName = "Microsoft"
},
new CustomerForLinq
{
Region = "WA",
CompanyName = "NewMonics"
},
new CustomerForLinq
{
Region = "OR",
CompanyName = "NewMonics"
},
new CustomerForLinq
{
Region = "CA",
CompanyName = "Microsoft"
},
};
customers.ForEach(i => context.Customers.Add(i));
new List<OrderForLinq>
{
new OrderForLinq
{
Total = 111M,
OrderDate = new DateTime(1997, 9, 3),
Customer = customers[0]
},
new OrderForLinq
{
Total = 222M,
OrderDate = new DateTime(2006, 9, 3),
Customer = customers[1]
},
new OrderForLinq
{
Total = 333M,
OrderDate = new DateTime(1999, 9, 3),
Customer = customers[0]
},
new OrderForLinq
{
Total = 444M,
OrderDate = new DateTime(2010, 9, 3),
Customer = customers[1]
},
new OrderForLinq
{
Total = 2555M,
OrderDate = new DateTime(2009, 9, 3),
Customer = customers[2]
},
new OrderForLinq
{
Total = 6555M,
OrderDate = new DateTime(1976, 9, 3),
Customer = customers[3]
},
new OrderForLinq
{
Total = 555M,
OrderDate = new DateTime(1985, 9, 3),
Customer = customers[2]
},
}.ForEach(i => context.Orders.Add(i));
}
}
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace BadMappingModel
{
public class Office
{
public int OfficeId { get; set; }
public string Name { get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Name2 { get; set; }
}
public class OnSiteEmployee : Employee
{
public Office Office { get; set; }
}
public class OffSiteEmployee : Employee
{
public string SiteName { get; set; }
}
}

Some files were not shown because too many files have changed in this diff Show More