├── src
├── EntityFramework.Metadata
│ ├── NuSpec
│ │ └── install.ps1
│ ├── packages.config
│ ├── Exceptions
│ │ └── ParentNotMappedYetException.cs
│ ├── Mappers
│ │ ├── TphData.cs
│ │ ├── CodeFirstMapper.cs
│ │ ├── DbFirstMapper.cs
│ │ └── MapperBase.cs
│ ├── App.config
│ ├── IDbMapping.cs
│ ├── EntityFramework.Metadata.nuspec
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Extensions
│ │ ├── MappingApiExtensions.cs
│ │ └── TypeExtensions.cs
│ ├── EfMap.cs
│ ├── IEntityMap.cs
│ ├── IPropertyMap.cs
│ ├── EntityFramework.Metadata.Net45.csproj
│ ├── EntityFramework.Metadata.csproj
│ └── Mappings
│ │ ├── DbMapping.cs
│ │ ├── PropertyMap.cs
│ │ └── EntityMap.cs
├── EntityFramework.Metadata.Test
│ ├── CodeFirst
│ │ ├── Domain
│ │ │ ├── Entity.cs
│ │ │ ├── EntityWithTypedId.cs
│ │ │ ├── EntityWithMappedPk.cs
│ │ │ ├── ComplexTypes
│ │ │ │ ├── Contact.cs
│ │ │ │ └── Address.cs
│ │ │ ├── Foo.cs
│ │ │ ├── MeteringPoint.cs
│ │ │ ├── PageTranslations.cs
│ │ │ ├── Reading.cs
│ │ │ ├── TestUser.cs
│ │ │ ├── House.cs
│ │ │ ├── Company.cs
│ │ │ ├── Page.cs
│ │ │ ├── Employee.cs
│ │ │ └── Contract.cs
│ │ ├── TestBase.cs
│ │ ├── TestContext.cs
│ │ ├── TestHelper.cs
│ │ ├── TphTest.cs
│ │ └── MappingTest.cs
│ ├── packages.config
│ ├── DbFirst
│ │ ├── TestModel.cs
│ │ ├── TestModel1.cs
│ │ ├── TestModel.Designer.cs
│ │ ├── TestModel1.Designer.cs
│ │ ├── Post.cs
│ │ ├── Blogs.cs
│ │ ├── TestModel.edmx.diagram
│ │ ├── TestModel.Context.cs
│ │ ├── TestModel.Context1.cs
│ │ ├── MappingTest.cs
│ │ ├── TestModel.edmx
│ │ └── TestModel.Context.tt
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── App.config
│ ├── EntityFramework.Metadata.Test.csproj
│ └── EntityFramework.Metadata.Test.Net45.csproj
├── EntityFramework.Metadata.sln
├── EntityFramework.Metadata.Net45.sln
├── .gitattributes
└── .gitignore
├── README.md
└── LICENSE
/src/EntityFramework.Metadata/NuSpec/install.ps1:
--------------------------------------------------------------------------------
1 | $DTE.ItemOperations.Navigate("https://github.com/schneidsDotNet/EntityFramework.Metadata/blob/master/README.md#entityframeworkmetadata")
2 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Entity.cs:
--------------------------------------------------------------------------------
1 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
2 | {
3 | public abstract class Entity : EntityWithTypedId
4 | {
5 |
6 | }
7 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/EntityWithTypedId.cs:
--------------------------------------------------------------------------------
1 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
2 | {
3 | public abstract class EntityWithTypedId
4 | {
5 | public T Id { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/EntityWithMappedPk.cs:
--------------------------------------------------------------------------------
1 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
2 | {
3 | public class EntityWithMappedPk
4 | {
5 | public int BancoId { get; set; }
6 | public string Nombre { get; set; }
7 | }
8 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Exceptions/ParentNotMappedYetException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace EntityFramework.Metadata.Exceptions
7 | {
8 | public class ParentNotMappedYetException : Exception
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/ComplexTypes/Contact.cs:
--------------------------------------------------------------------------------
1 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain.ComplexTypes
2 | {
3 | public class Contact
4 | {
5 | public string PhoneNumber { get; set; }
6 | public Address BusinessAddress { get; set; }
7 | public Address ShippingAddress { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Foo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
7 | {
8 | public class Foo
9 | {
10 | public int Id { get; set; }
11 | public string Bar { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/MeteringPoint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
4 | {
5 | public class MeteringPoint : Entity
6 | {
7 | public string EIC { get; set; }
8 |
9 | public DateTime CreatedAt { get; set; }
10 | public DateTime? ModifiedAt { get; set; }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/PageTranslations.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
3 | {
4 | public class PageTranslations
5 | {
6 | public int PageId { get; set; }
7 |
8 | public virtual Page Page { get; set; }
9 |
10 | public string Language { get; set; }
11 |
12 | public string Title { get; set; }
13 |
14 | public string Content { get; set; }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Mappers/TphData.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Data.Entity.Core.Metadata.Edm;
3 |
4 | namespace EntityFramework.Metadata.Mappers
5 | {
6 | internal class TphData
7 | {
8 | public EdmMember[] Properties { get; set; }
9 | public NavigationProperty[] NavProperties { get; set; }
10 |
11 | public Dictionary Discriminators = new Dictionary();
12 | }
13 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Reading.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
4 | {
5 | public class Reading : Entity
6 | {
7 | public int MeteringPointId { get; set; }
8 | public virtual MeteringPoint MeteringPoint { get; set; }
9 | public DateTime Date { get; set; }
10 | public decimal? Consumed { get; set; }
11 | public decimal? Produced { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel1.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/TestUser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using EntityFramework.Metadata.Test.CodeFirst.Domain.ComplexTypes;
3 |
4 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
5 | {
6 | public class TestUser : EntityWithTypedId
7 | {
8 | public Contact Contact { get; set; }
9 | public string FirstName { get; set; }
10 | public string LastName { get; set; }
11 | public string FullName { get { return string.Format("{0} {1}", FirstName, LastName); }}
12 | }
13 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/House.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using EntityFramework.Metadata.Test.CodeFirst.Domain.ComplexTypes;
7 |
8 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
9 | {
10 | public class House
11 | {
12 | public int Id { get; set; }
13 |
14 | public string Name { get; set; }
15 |
16 | // complex type must be the last member
17 | public Address Address { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/ComplexTypes/Address.cs:
--------------------------------------------------------------------------------
1 | using System.Data.Entity.Spatial;
2 |
3 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain.ComplexTypes
4 | {
5 | public class Address
6 | {
7 | public string Country { get; set; }
8 | public string County { get; set; }
9 | public string City { get; set; }
10 | public string PostalCode { get; set; }
11 | public string StreetAddress { get; set; }
12 |
13 | #if !NET40
14 | public DbGeography Location { get; set; }
15 | public DbGeometry Shape { get; set; }
16 | #endif
17 | }
18 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Company.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using EntityFramework.Metadata.Test.CodeFirst.Domain.ComplexTypes;
7 |
8 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
9 | {
10 | public class Company
11 | {
12 | public int Id { get; set; }
13 | public string Name { get; set; }
14 | public Contact FirstContact { get; set; }
15 | public Contact SecondContact { get; set; }
16 | public Address BusinessAddress { get; set; }
17 | public Address ShippingAddress { get; set; }
18 | public DateTime BusinessStartDate { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/IDbMapping.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EntityFramework.Metadata
4 | {
5 | public interface IDbMapping
6 | {
7 | ///
8 | /// Tables in database
9 | ///
10 | ITableMapping[] Tables { get; }
11 |
12 | ///
13 | /// Get table mapping by entity type
14 | ///
15 | ///
16 | ///
17 | ITableMapping this[Type type] { get; }
18 |
19 | ///
20 | /// Get table mapping by entity type full name
21 | ///
22 | ///
23 | ///
24 | ITableMapping this[string typeFullName] { get; }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel.Designer.cs:
--------------------------------------------------------------------------------
1 | // T4 code generation is enabled for model 'C:\dev\EntityFramework.Metadata\trunk\src\EntityFramework.Metadata.Test\DbFirst\TestModel.edmx'.
2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer
3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model
4 | // is open in the designer.
5 |
6 | // If no context and entity classes have been generated, it may be because you created an empty model but
7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity
8 | // classes for your model, open the model in the designer, right-click on the designer surface, and
9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation
10 | // Item...'.
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel1.Designer.cs:
--------------------------------------------------------------------------------
1 | // T4 code generation is enabled for model 'D:\Development\EntityFramework.MappingApi\EntityFramework.Metadata.Test\DbFirst\TestModel.edmx'.
2 | // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer
3 | // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model
4 | // is open in the designer.
5 |
6 | // If no context and entity classes have been generated, it may be because you created an empty model but
7 | // have not yet chosen which version of Entity Framework to use. To generate a context class and entity
8 | // classes for your model, open the model in the designer, right-click on the designer surface, and
9 | // select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation
10 | // Item...'.
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Page.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
5 | {
6 | public class Page
7 | {
8 | public int PageId { get; set; }
9 |
10 | public string Content { get; set; }
11 |
12 | public string Title { get; set; }
13 |
14 | public int? ParentId { get; set; }
15 |
16 | public virtual Page Parent { get; set; }
17 |
18 | public virtual ICollection Translations { get; set; }
19 |
20 | public Guid CreatedById { get; set; }
21 | public virtual TestUser CreatedBy { get; set; }
22 | public DateTime CreatedAt { get; set; }
23 |
24 | public Guid? ModifiedById { get; set; }
25 | public virtual TestUser ModifiedBy { get; set; }
26 | public DateTime? ModifiedAt { get; set; }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/Post.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 | namespace EntityFramework.Metadata.Test.DbFirst
11 | {
12 | using System;
13 | using System.Collections.Generic;
14 |
15 | public partial class Post
16 | {
17 | public int PostId { get; set; }
18 | public string Title { get; set; }
19 | public string Content { get; set; }
20 | public int BlogId { get; set; }
21 |
22 | public virtual Blogs Blogs { get; set; }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/Blogs.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 | namespace EntityFramework.Metadata.Test.DbFirst
11 | {
12 | using System;
13 | using System.Collections.Generic;
14 |
15 | public partial class Blogs
16 | {
17 | public Blogs()
18 | {
19 | this.Posts = new HashSet();
20 | }
21 |
22 | public int BlogId { get; set; }
23 | public string Name { get; set; }
24 | public string Url { get; set; }
25 |
26 | public virtual ICollection Posts { get; set; }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel.edmx.diagram:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel.Context.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 | namespace EntityFramework.Metadata.Test.DbFirst
11 | {
12 | using System;
13 | using System.Data.Entity;
14 | using System.Data.Entity.Infrastructure;
15 |
16 | public partial class efmapping_testEntities : DbContext
17 | {
18 | public efmapping_testEntities()
19 | : base("name=efmapping_testEntities")
20 | {
21 | }
22 |
23 | protected override void OnModelCreating(DbModelBuilder modelBuilder)
24 | {
25 | throw new UnintentionalCodeFirstException();
26 | }
27 |
28 | public virtual DbSet Blogs { get; set; }
29 | public virtual DbSet Posts { get; set; }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/DbFirst/TestModel.Context1.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated from a template.
4 | //
5 | // Manual changes to this file may cause unexpected behavior in your application.
6 | // Manual changes to this file will be overwritten if the code is regenerated.
7 | //
8 | //------------------------------------------------------------------------------
9 |
10 | namespace EntityFramework.Metadata.Test.DbFirst
11 | {
12 | using System;
13 | using System.Data.Entity;
14 | using System.Data.Entity.Infrastructure;
15 |
16 | public partial class efmapping_testEntities : DbContext
17 | {
18 | public efmapping_testEntities()
19 | : base("name=efmapping_testEntities")
20 | {
21 | }
22 |
23 | protected override void OnModelCreating(DbModelBuilder modelBuilder)
24 | {
25 | throw new UnintentionalCodeFirstException();
26 | }
27 |
28 | public virtual DbSet Blogs { get; set; }
29 | public virtual DbSet Posts { get; set; }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EntityFramework.Metadata #
2 | [](https://www.nuget.org/packages/EntityFramework.Metadata/)
3 |
4 | Get table metadata for your Entity Framework entities. Need to know the table name of your entity programatically? Schema name? Column name from a property? EntityFramework.Metadata has that and more.
5 |
6 | static void Main()
7 | {
8 | var context = new MyDbContext();
9 | var personData = context.Db();
10 |
11 | Console.WriteLine(personData.TableName);
12 | // output: People
13 |
14 | var nameColumn = personData.Prop("Name");
15 |
16 | Console.WriteLine(nameColumn.ColumnName);
17 | // output: MyName
18 | }
19 |
20 | [Table("People")]
21 | public class Person
22 | {
23 | public int PersonId { get; set; }
24 | [Column("MyName")]
25 | public string Name { get; set; }
26 | }
27 |
28 | Forked from [EntityFramework.MappingAPI](https://efmappingapi.codeplex.com/) by Markko Legonkov. Fixed bugs, added some unit tests, simplified the code and project structure, and removed support for EF5 and below.
29 |
30 | ### License ###
31 | This project is licensed under the MIT license. Portions of the code are subject to the BSD Simplified license - see LICENSE for more info.
32 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/EntityFramework.Metadata.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | EntityFramework.Metadata
5 | $version$
6 | EntityFramework.Metadata
7 | Spencer Schneidenbach
8 | Spencer Schneidenbach
9 | https://github.com/schneidsDotNet/EntityFramework.Metadata/blob/master/LICENSE
10 | https://github.com/schneidsDotNet/EntityFramework.Metadata
11 | false
12 | Table metadata provider for your Entity Framework entities.
13 | Table metadata provider for your Entity Framework entities.
14 | Copyright 2016
15 | EntityFramework
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Employee.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
4 | {
5 | public abstract class EmployeeTPT
6 | {
7 | public int Id { get; set; }
8 | public string Name { get; set; }
9 | public string JobTitle { get; set; }
10 | }
11 |
12 | public class WorkerTPT : EmployeeTPT
13 | {
14 | public int? RefereeId { get; set; }
15 | public virtual WorkerTPT Referee { get; set; }
16 | public virtual ManagerTPT Boss { get; set; }
17 | }
18 |
19 | public class ManagerTPT : EmployeeTPT
20 | {
21 | public string Rank { get; set; }
22 | public virtual ICollection Henchmen { get; set; }
23 | }
24 |
25 |
26 | public abstract class EmployeeTPH
27 | {
28 | public string NameWithTitle { get { return string.Format("{0} ({1})", Name, Title); } }
29 |
30 | public int Id { get; set; }
31 | public string Name { get; set; }
32 | public string Title { get; set; }
33 | }
34 |
35 | public class AWorkerTPH : EmployeeTPH
36 | {
37 | public int BossId { get; set; }
38 | public int RefId { get; set; }
39 | public virtual ManagerTPH Boss { get; set; }
40 | }
41 |
42 | public class ManagerTPH : EmployeeTPH
43 | {
44 | public string Rank { get; set; }
45 | public int? RefId { get; set; }
46 | public virtual ICollection Henchmen { get; set; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("EntityFramework.Metadata")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("EntityFramework.Metadata")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid("79ca2e96-9fed-4351-975c-6009c381c3a8")]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 |
37 | [assembly: AssemblyVersion("1.0.1.0")]
38 | [assembly: AssemblyFileVersion("1.0.1.0")]
39 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("EntityFramework.Metadata.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("EntityFramework.Metadata.Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("e923c408-9b21-4ff4-8d71-14b8ad16f5a8")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/TestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Entity;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using NUnit.Framework;
6 |
7 | namespace EntityFramework.Metadata.Test.CodeFirst
8 | {
9 | [TestFixture]
10 | public abstract class TestBase
11 | {
12 | protected const int NvarcharMax = 1073741823;
13 | [SetUp]
14 | public virtual void Setup()
15 | {
16 | if (!Database.Exists("TestContext"))
17 | {
18 | Database.SetInitializer(new CreateDatabaseIfNotExists());
19 | }
20 | else
21 | {
22 | Database.SetInitializer(null);
23 | }
24 | }
25 |
26 | protected TestContext GetContext()
27 | {
28 | var ctx = new TestContext();
29 |
30 | ctx.Configuration.AutoDetectChangesEnabled = false;
31 | ctx.Configuration.LazyLoadingEnabled = false;
32 | ctx.Configuration.ProxyCreationEnabled = false;
33 | ctx.Configuration.ValidateOnSaveEnabled = false;
34 |
35 | return ctx;
36 | }
37 |
38 | protected void InitializeContext()
39 | {
40 | using (var ctx = GetContext())
41 | {
42 | var sw = new Stopwatch();
43 | sw.Start();
44 | var tmp = ctx.Pages.Count();
45 | sw.Stop();
46 | Console.WriteLine("Initializing dbmodel took: {0}ms", sw.Elapsed.TotalMilliseconds);
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.Metadata", "EntityFramework.Metadata\EntityFramework.Metadata.csproj", "{609BE91A-F11B-49BC-98D9-F7C83517A59E}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.Metadata.Test", "EntityFramework.Metadata.Test\EntityFramework.Metadata.Test.csproj", "{C9530AA5-ACAD-4892-96E8-987A7847C341}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {609BE91A-F11B-49BC-98D9-F7C83517A59E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {609BE91A-F11B-49BC-98D9-F7C83517A59E}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {609BE91A-F11B-49BC-98D9-F7C83517A59E}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {609BE91A-F11B-49BC-98D9-F7C83517A59E}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {C9530AA5-ACAD-4892-96E8-987A7847C341}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {C9530AA5-ACAD-4892-96E8-987A7847C341}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {C9530AA5-ACAD-4892-96E8-987A7847C341}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {C9530AA5-ACAD-4892-96E8-987A7847C341}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Net45.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.Metadata.Net45", "EntityFramework.Metadata\EntityFramework.Metadata.Net45.csproj", "{168DD262-C4DB-49E8-BF62-BFDD3B6DA41E}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.Metadata.Test.Net45", "EntityFramework.Metadata.Test\EntityFramework.Metadata.Test.Net45.csproj", "{BC13B004-21FE-4A7A-8B8B-728E4A9CEC67}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {168DD262-C4DB-49E8-BF62-BFDD3B6DA41E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {168DD262-C4DB-49E8-BF62-BFDD3B6DA41E}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {168DD262-C4DB-49E8-BF62-BFDD3B6DA41E}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {168DD262-C4DB-49E8-BF62-BFDD3B6DA41E}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {BC13B004-21FE-4A7A-8B8B-728E4A9CEC67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {BC13B004-21FE-4A7A-8B8B-728E4A9CEC67}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {BC13B004-21FE-4A7A-8B8B-728E4A9CEC67}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {BC13B004-21FE-4A7A-8B8B-728E4A9CEC67}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Extensions/MappingApiExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Data.Entity;
3 | using System.Linq.Expressions;
4 |
5 | namespace EntityFramework.Metadata.Extensions
6 | {
7 | public static class MappingApiExtensions
8 | {
9 | ///
10 | ///
11 | ///
12 | ///
13 | ///
14 | public static IEntityMap[] Db(this DbContext ctx)
15 | {
16 | return EfMap.Get(ctx).Tables;
17 | }
18 |
19 | ///
20 | ///
21 | ///
22 | ///
23 | ///
24 | ///
25 | public static IEntityMap Db(this DbContext ctx)
26 | {
27 | return EfMap.Get(ctx);
28 | }
29 |
30 | ///
31 | ///
32 | ///
33 | ///
34 | ///
35 | ///
36 | ///
37 | ///
38 | public static IEntityMap Db(this T ctx, Expression>> dbset) where T : DbContext where T1 : class
39 | {
40 | return ctx.Db();
41 | }
42 |
43 | ///
44 | ///
45 | ///
46 | ///
47 | ///
48 | ///
49 | public static IEntityMap Db(this DbContext ctx, Type type)
50 | {
51 | return EfMap.Get(ctx)[type];
52 | }
53 |
54 | ///
55 | ///
56 | ///
57 | ///
58 | ///
59 | ///
60 | public static IEntityMap Db(this DbContext ctx, string typeFullName)
61 | {
62 | return EfMap.Get(ctx)[typeFullName];
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Mappers/CodeFirstMapper.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using EntityFramework.Metadata.Exceptions;
4 | using System.Data.Entity.Core.Metadata.Edm;
5 |
6 | namespace EntityFramework.Metadata.Mappers
7 | {
8 | internal class CodeFirstMapper : MapperBase
9 | {
10 | public CodeFirstMapper(MetadataWorkspace metadataWorkspace, EntityContainer entityContainer)
11 | : base(metadataWorkspace, entityContainer)
12 | {
13 | }
14 |
15 | protected string GetTableName(EntitySet entitySet)
16 | {
17 | return (string)entitySet.MetadataProperties["Table"].Value;
18 | }
19 |
20 | protected override PrepareMappingRes PrepareMapping(string typeFullName, EdmType edmItem)
21 | {
22 | // find existing parent storageEntitySet
23 | // thp derived types does not have storageEntitySet
24 | EntitySet storageEntitySet;
25 | EdmType baseEdmType = edmItem;
26 | while (!EntityContainer.TryGetEntitySetByName(baseEdmType.Name, false, out storageEntitySet))
27 | {
28 | if (baseEdmType.BaseType == null)
29 | {
30 | break;
31 | }
32 | baseEdmType = baseEdmType.BaseType;
33 | }
34 |
35 | if (storageEntitySet == null)
36 | {
37 | return null;
38 | }
39 |
40 | var isRoot = baseEdmType == edmItem;
41 | if (!isRoot)
42 | {
43 | var parent = _entityMaps.Values.FirstOrDefault(x => x.EdmType == baseEdmType);
44 | // parent table has not been mapped yet
45 | if (parent == null)
46 | {
47 | throw new ParentNotMappedYetException();
48 | }
49 | }
50 |
51 | string tableName = GetTableName(storageEntitySet);
52 |
53 | return new PrepareMappingRes { TableName = tableName, StorageEntitySet = storageEntitySet, IsRoot = isRoot, BaseEdmType = baseEdmType };
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/EfMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using EntityFramework.Metadata.Mappings;
5 | using System.Data.Entity.Infrastructure;
6 |
7 | namespace EntityFramework.Metadata
8 | {
9 | ///
10 | ///
11 | ///
12 | internal class EfMap
13 | {
14 | ///
15 | ///
16 | ///
17 | private static readonly Dictionary Mappings = new Dictionary();
18 |
19 | ///
20 | ///
21 | ///
22 | ///
23 | ///
24 | ///
25 | public static IEntityMap Get(DbContext context)
26 | {
27 | return (IEntityMap)Get(context)[typeof(T)];
28 | }
29 |
30 | ///
31 | ///
32 | ///
33 | ///
34 | public static IEntityMap Get(DbContext context, Type type)
35 | {
36 | return Get(context)[type];
37 | }
38 |
39 | ///
40 | ///
41 | ///
42 | ///
43 | public static IEntityMap Get(DbContext context, string typeFullName)
44 | {
45 | return Get(context)[typeFullName];
46 | }
47 |
48 | ///
49 | ///
50 | ///
51 | ///
52 | ///
53 | public static DbMapping Get(DbContext context)
54 | {
55 | var cackeKey = context.GetType().FullName;
56 |
57 | var iDbModelCacheKeyProvider = context as IDbModelCacheKeyProvider;
58 | if (iDbModelCacheKeyProvider != null)
59 | {
60 | cackeKey = iDbModelCacheKeyProvider.CacheKey;
61 | }
62 |
63 | if (Mappings.ContainsKey(cackeKey))
64 | {
65 | return Mappings[cackeKey];
66 | }
67 |
68 | var mapping = new DbMapping(context);
69 | //var mapping = Map(context);
70 |
71 | Mappings[cackeKey] = mapping;
72 | return mapping;
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/IEntityMap.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Linq.Expressions;
4 | using System.Security.Cryptography.X509Certificates;
5 |
6 | namespace EntityFramework.Metadata
7 | {
8 | ///
9 | /// Generic entity map
10 | ///
11 | /// Entity type
12 | public interface IEntityMap : IEntityMap
13 | {
14 | ///
15 | /// Get property mapping by predicate
16 | ///
17 | ///
18 | ///
19 | ///
20 | IPropertyMap Prop(Expression> predicate);
21 | }
22 |
23 | public interface IEntityMap
24 | {
25 | ///
26 | /// Entity type
27 | ///
28 | Type Type { get; }
29 |
30 | ///
31 | /// Table name in database
32 | ///
33 | string TableName { get; }
34 |
35 | ///
36 | /// Table schema
37 | ///
38 | string Schema { get; }
39 |
40 | ///
41 | /// Is table-per-hierarchy mapping
42 | ///
43 | bool IsTph { get; }
44 |
45 | ///
46 | /// Is table-per-hierarchy base entity
47 | ///
48 | bool IsRoot { get; }
49 |
50 | ///
51 | /// Mapped properties
52 | ///
53 | IPropertyMap[] Properties { get; }
54 |
55 | ///
56 | /// Foreign key properties
57 | ///
58 | IPropertyMap[] Fks { get; }
59 |
60 | ///
61 | /// Primary key properties
62 | ///
63 | IPropertyMap[] Pks { get; }
64 |
65 | ///
66 | /// Tph entity discriminators
67 | ///
68 | IPropertyMap[] Discriminators { get; }
69 |
70 | ///
71 | /// Gets property map by property name
72 | ///
73 | ///
74 | ///
75 | IPropertyMap this[string property] { get; }
76 |
77 | ///
78 | /// Gets property map by property name
79 | ///
80 | ///
81 | ///
82 | IPropertyMap Prop(string propertyName);
83 | }
84 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Spencer Schneidenbach
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
24 |
25 |
26 | Code initially forked from http://efmappingapi.codeplex.com is licensed under BSD Simplified
27 |
28 | Copyright (c) 2014, Markko Legonkov
29 | All rights reserved.
30 |
31 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
32 |
33 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
34 |
35 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
36 |
37 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 |
39 |
--------------------------------------------------------------------------------
/src/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata.Test/CodeFirst/Domain/Contract.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace EntityFramework.Metadata.Test.CodeFirst.Domain
4 | {
5 | public abstract class ContractBase : Entity
6 | {
7 | public string ContractNr { get; set; }
8 | public string AvpContractNr { get; set; }
9 |
10 | public int MeteringPointId { get; set; }
11 | public virtual MeteringPoint MeteringPoint { get; set; }
12 |
13 | public DateTime StartDate { get; set; }
14 |
15 | public DateTime? EndDate { get; set; }
16 |
17 | public DateTime? ContractSignedAt { get; set; }
18 |
19 | ///
20 | /// Utc time of contract start date. Readonly
21 | ///
22 | public DateTime StartDateUtc { get; protected set; }
23 |
24 | ///
25 | /// Utc time of contract end date. Readonly
26 | ///
27 | public DateTime? EndDateUtc { get; protected set; }
28 |
29 | public int ClientId { get; set; }
30 |
31 | public decimal? FixedPrice { get; set; }
32 |
33 | public int? PackageId { get; set; }
34 | public string PackageName { get; set; }
35 |
36 | public bool Validated { get; set; }
37 |
38 | public DateTime CreatedAt { get; set; }
39 | public DateTime? ModifiedAt { get; set; }
40 | public DateTime? LastPricesCalculatedAt { get; set; }
41 |
42 | protected ContractBase()
43 | {
44 | StartDate = DateTime.Now;
45 | StartDateUtc = DateTime.Now;
46 | CreatedAt = DateTime.Now;
47 | }
48 | }
49 |
50 | public class Contract : ContractBase
51 | {
52 |
53 | }
54 |
55 | public class ContractFixed : ContractBase
56 | {
57 | public int PackageFixedId { get; set; }
58 |
59 | public string PricesJson { get; set; }
60 | }
61 |
62 | public class ContractStock : ContractBase
63 | {
64 | public decimal? Margin { get; set; }
65 |
66 | public int PackageStockId { get; set; }
67 | }
68 |
69 | public class ContractKomb1 : ContractBase
70 | {
71 | public int PackageKomb1Id { get; set; }
72 |
73 | public decimal Base { get; set; }
74 | public decimal? StockMargin { get; set; }
75 | public string FixPricesJson { get; set; }
76 |
77 | public int SubPackageId { get; set; }
78 | }
79 |
80 | public class ContractKomb2 : ContractBase
81 | {
82 | public int PackageKomb2Id { get; set; }
83 |
84 | public decimal? Part1Margin { get; set; }
85 | public string Part1PricesJson { get; set; }
86 |
87 | public int Part1SubPackageId { get; set; }
88 |
89 | public decimal? Part2Margin { get; set; }
90 | public string Part2PricesJson { get; set; }
91 |
92 | public int Part2SubPackageId { get; set; }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/EntityFramework.Metadata/Mappers/DbFirstMapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using EntityFramework.Metadata.Exceptions;
5 | using EntityFramework.Metadata.Extensions;
6 | using System.Data.Entity.Core.Mapping;
7 | using System.Data.Entity.Core.Metadata.Edm;
8 |
9 |
10 | namespace EntityFramework.Metadata.Mappers
11 | {
12 | internal class DbFirstMapper : MapperBase
13 | {
14 | public DbFirstMapper(MetadataWorkspace metadataWorkspace, EntityContainer entityContainer)
15 | : base(metadataWorkspace, entityContainer)
16 | {
17 | }
18 |
19 | protected override PrepareMappingRes PrepareMapping(string typeFullName, EdmType edmItem)
20 | {
21 | string tableName = GetTableName(typeFullName);
22 |
23 | // find existing parent storageEntitySet
24 | // thp derived types does not have storageEntitySet
25 | EntitySet storageEntitySet;
26 | EdmType baseEdmType = edmItem;
27 | while (!EntityContainer.TryGetEntitySetByName(tableName, false, out storageEntitySet))
28 | {
29 | if (baseEdmType.BaseType == null)
30 | {
31 | break;
32 | }
33 | baseEdmType = baseEdmType.BaseType;
34 | }
35 |
36 | if (storageEntitySet == null)
37 | {
38 | return null;
39 | }
40 |
41 | var isRoot = baseEdmType == edmItem;
42 | if (!isRoot)
43 | {
44 | var parent = _entityMaps.Values.FirstOrDefault(x => x.EdmType == baseEdmType);
45 | // parent table has not been mapped yet
46 | if (parent == null)
47 | {
48 | throw new ParentNotMappedYetException();
49 | }
50 | }
51 |
52 | return new PrepareMappingRes { TableName = tableName, StorageEntitySet = storageEntitySet, IsRoot = isRoot, BaseEdmType = baseEdmType };
53 | }
54 |
55 | protected string GetTableName(string typeFullName)
56 | {
57 | // Get the entity type from the model that maps to the CLR type
58 | var entityType = MetadataWorkspace.GetItems(DataSpace.OSpace).Single(e => e.FullName == typeFullName);
59 |
60 | // Get the entity set that uses this entity type
61 | var entitySet = MetadataWorkspace
62 | .GetItems(DataSpace.CSpace)
63 | .Single()
64 | .EntitySets
65 | .Single(s => s.ElementType.Name == entityType.Name);
66 |
67 | var entitySetMappings = (IEnumerable