LinqPad and EntityTypeConfiguration

How can I get LinqPad to recognize when entities are using configuration files instead of or in addition to table and property attributes?

Comments

  • What version of LINQPad are you using, and that version of EF?

  • LINQPad version - 5.41.00
    EF - 6.1.3

  • Are you referring to the app.config file or the EDM files? Are you using ObjectContext or DbContext? What have you tried so far and what's the result?

  • I have several projects in the solution. One contains the entities, and another contains the configuration files that define table names, key fields, property types, lengths, etc.

    I am using DbContext and have included the configuration project dll, but get the following messages:

    ModelValidationException: One or more validation errors were detected during model generation:

    CodeFirstNamespace.ContractDocument: : EntityType 'ContractDocument' has no key defined. Define the key for this EntityType.

    Is there a way to get LINQPad to recognize the configurations?

    Thanks

  • In what format are the configuration files, and what code is responsible for reading them?

  • I am using the Fluent API for property mapping.

    Here is an example:

    //==============
    // Region.cs
    //==============
    namespace MyProject.Entities
    {
    using System.ComponentModel.DataAnnotations;

    public class Region
    {
        public int RegionId { get; set; }
    
        [Required(ErrorMessage = "Region Name is required")]
        [StringLength(100, ErrorMessage = "Region can not be more than 100 characters")]
        public string RegionName { get; set; }
    }
    

    }

    //=====================
    // RegionConfiguration.cs
    //=====================
    namespace MyProject.Data.Configuration
    {
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.ModelConfiguration;
    using Entities;

    public class RegionConfiguration: EntityTypeConfiguration<Region>
    {
        public RegionConfiguration()
        {
            ToTable("Region");
            HasKey(x => x.RegionId);
            Property(x => x.RegionId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
        }
    }
    

    }

Sign In or Register to comment.