Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:18:51+00:00 2026-06-15T19:18:51+00:00

I am going to create code-first view by using a T4 template like the

  • 0

I am going to create code-first view by using a T4 template like the below mentioned article says:

Article here

But it’s causing an

run time exception

like below. Why’s that?

My connection string is configured properly in App.config.

My application is N-Tier based.So That DbContext driven class is in Data Layer.

This is my connection String:

<add name="PawLoyalty" connectionString="Server=.;database=PawLoyalty;Trusted_connection=true;pooling=true;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

I am using EF 4.1 with vs 2010.

Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.

—> System.ArgumentException: The argument ‘nameOrConnectionString’ cannot be null, empty or contain only white space.

at System.Data.Entity.ModelConfiguration.Utilities.RuntimeFailureMethods.ReportFailure(ContractFailureKind contractFailureKind, String userMessage, String conditionText,
Exception innerException)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at PawLoyalty.Data.DataCatalog..ctor(Boolean allowLazyLoading) in D:\My Blog\Test
Projects\PawLoyalty\PawLoyalty\PawLoyalty.Data\DataCatalog.cs:line 31
at PawLoyalty.Data.DataCatalog..ctor() in D:\My Blog\Test Projects\PawLoyalty\PawLoyalty\PawLoyalty.Data\DataCatalog.cs:line 26
— End of inner exception stack trace —
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&
stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.VisualStudio.TextTemplatingD6E95B37BD0790EBBCC7DB570AD3E2AC.GeneratedTextTransformation.GetEdmx(Type
contextType)
at Microsoft.VisualStudio.TextTemplatingD6E95B37BD0790EBBCC7DB570AD3E2AC.GeneratedTextTransformation.GenerateViews(String contextTypeName)
at Microsoft.VisualStudio.TextTemplatingD6E95B37BD0790EBBCC7DB570AD3E2AC.GeneratedTextTransformation.TransformText()
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession
session, String source, ITextTemplatingEngineHost host, String&
result)

Updated

My DbContext Derived class looks like below.

 [Export(typeof(ISecurityDataCatalog))]
    [Export(typeof(IMappingDataCatalog))]
    [Export(typeof(IPawLoyaltyDataCatalog))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class DataCatalog : DbContext, IPawLoyaltyDataCatalog, ISecurityDataCatalog, IMappingDataCatalog
    {

        public static string ConnectionString { get; set; }
        public static string AccountToken { get; set; }

        public DataCatalog()
            : this(false)
        {
        }

        public DataCatalog(bool allowLazyLoading = false)
            : base(ConnectionString)
        {
            Configuration.LazyLoadingEnabled = allowLazyLoading;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.ComplexType<DiscountValue>().Property(d => d.Fixed).HasPrecision(18, 2);
            modelBuilder.ComplexType<DiscountValue>().Property(d => d.Percentage).HasPrecision(18, 4);
            modelBuilder.Entity<InvoiceFee>().Property(d => d.Fixed).HasPrecision(18, 2);
            modelBuilder.Entity<InvoiceFee>().Property(d => d.Percentage).HasPrecision(18, 4);
            modelBuilder.Entity<InvoiceFee>().Property(d => d.Total).HasPrecision(18, 4);
            modelBuilder.Entity<Invoice>().Property(d => d.Discount).HasPrecision(18, 2);
            modelBuilder.Entity<Invoice>().HasRequired(i => i.Appointment).WithOptional(a => a.Invoice).WillCascadeOnDelete(false);
            modelBuilder.Entity<InvoiceItem>().Property(d => d.Price).HasPrecision(18, 2);
            modelBuilder.Entity<InvoiceItem>().Property(d => d.LatestTotal).HasPrecision(18, 2);
            modelBuilder.Entity<InvoiceItem>().HasRequired(i => i.Allocation).WithOptional(a => a.InvoiceItem).WillCascadeOnDelete(false);
            modelBuilder.Entity<InvoicePayment>().Property(d => d.Amount).HasPrecision(18, 4);
            modelBuilder.Entity<ServicePrice>().Property(d => d.Price).HasPrecision(18, 2);
            modelBuilder.Entity<ServiceBreedPrice>().Property(d => d.Price).HasPrecision(18, 2);
            modelBuilder.Entity<ProviderPolicy>().Property(d => d.SalesTax).HasPrecision(18, 4);
            modelBuilder.Entity<ProviderCredit>().Property(d => d.Balance).HasPrecision(18, 2);
            modelBuilder.Entity<CombinedServiceDiscountDefinition>().HasRequired(c => c.PrimaryService).WithMany().WillCascadeOnDelete(false);
            modelBuilder.Entity<CombinedServiceDiscountDefinition>().HasRequired(c => c.SecondaryService).WithMany().WillCascadeOnDelete(false);

            modelBuilder.Entity<MedicalRecord>().HasRequired(m => m.Pet).WithOptional(p => p.Medical).WillCascadeOnDelete(false);
            modelBuilder.Entity<BehavioralRecord>().HasRequired(b => b.Pet).WithOptional(p => p.Behavioral).WillCascadeOnDelete(false);
            modelBuilder.Entity<DietRecord>().HasRequired(d => d.Pet).WithOptional(p => p.Diet).WillCascadeOnDelete(false);

            modelBuilder.Entity<Provider>().HasOptional(p => p.Profile).WithRequired(p => p.Provider).WillCascadeOnDelete(true);

            modelBuilder.Entity<ProviderProfile>().HasOptional(p => p.Policy).WithRequired(p => p.Profile).WillCascadeOnDelete(true);
            modelBuilder.Entity<ProviderProfile>().HasOptional(p => p.CustomerRequirements).WithRequired(p => p.Profile).WillCascadeOnDelete(true);
            modelBuilder.Entity<ProviderProfile>().HasOptional(p => p.PaymentProfile).WithRequired(p => p.Profile).WillCascadeOnDelete(true);

            modelBuilder.Entity<Resource>().HasMany(r => r.Availability).WithRequired(a => a.Resource).WillCascadeOnDelete(true);

            Database.SetInitializer<DataCatalog>(null);
            base.OnModelCreating(modelBuilder);
        }

        public const string ServiceKey = "PawLoyalty";

        public DbSet<StreetAddress> StreetAddresses { get; set; }
        public DbSet<Appointment> Appointments { get; set; }
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<InsuranceCarrier> InsuranceCarriers { get; set; }
        public DbSet<PromotionCode> PromotionCodes { get; set; }

        // Provider Classes
        public DbSet<Provider> Providers { get; set; }
        public DbSet<ProviderProfile> ProviderProfiles { get; set; }
        //public DbSet<ProviderResourceItem> ProviderResourceItems { get; set; }
        public DbSet<Allocation> ResourceAllocations { get; set; }
        public DbSet<ResourceAvailability> ResourceAvailabilities { get; set; }
        public DbSet<Resource> Resources { get; set; }

        /// <summary>
        /// Wraps the object context detach method
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        public void Detach<T>(T t) where T : class
        {
            // TODO: Is this needed? Hidden behind an interface in CTP5 implying infrequent usage.
            ((IObjectContextAdapter)this).ObjectContext.Detach(t);
        }

        // Owner Classes
        public DbSet<MedicalRecordOrder> Orders { get; set; }
        public DbSet<Owner> Owners { get; set; }
        public DbSet<Pet> Pets { get; set; }
        public DbSet<Breed> Breeds { get; set; }
        public DbSet<PetProvider> PetProviders { get; set; }

        // Security Catalog Items
        public DbSet<User> Users { get; set; }

        // Bing Maps Catalog items
        public DbSet<KnownLocation> KnownLocations { get; set; }
        public DbSet<KnownPostalCode> KnownPostalCodes { get; set; }

        public DbSet<QueuedEmail> QueuedEmails { get; set; }
        public DbSet<InvoicePayment> InvoicePayments { get; set; }
        public DbSet<Employee> Employees { get; set; }
        public DbSet<Schedule> Schedules { get; set; }
        public DbSet<Subscription> Subscriptions { get; set; }
        public DbSet<EmailSubscription> EmailSubscriptions { get; set; }

        public DbSet<ResourceAvailabilityUpdate> ResourceAvailabilityUpdates { get; set; }
        public DbSet<EmployeeAvailabilityUpdate> EmployeeAvailabilityUpdates { get; set; }
        public DbSet<InvoiceConfiguration> InvoiceConfigurations { get; set; }

        public DbSet<Vaccine> Vaccines { get; set; }
        public DbSet<TourEmail> TourEmails { get; set; }
        public DbSet<ReservationRequest> ReservationRequest { get; set; }
        //public DbSet<ReservationRequestPets> ReservationRequestPets { get; set; }
        public DbSet<Vaccination> Vaccinations { get; set; }
        public DbSet<SpecialInstruction> SpecialInstructions { get; set; }

        public DbSet<Product> Products { get; set; }
        public DbSet<ProductCategory> ProductCategories { get; set; }
        public DbSet<VendorStock> VendorStocks { get; set; }
        public DbSet<ShoppingCart> ShoppingCarts { get; set; }
        public DbSet<SaleDetail> SaleDetails { get; set; }
        public DbSet<Sale> Sales { get; set; }
        public DbSet<SalePayment> SalePayments { get; set; }

        public DbSet<PetService> PetServices { get; set; }
        public DbSet<PetServicePrice> PetServicePrices { get; set; }

        public DbSet<MiscProperty> MiscProperties { get; set; }
        public DbSet<ProviderMiscProperty> ProviderMiscProperties { get; set; }

        public DbSet<ProviderAuthorizedCreditCard> ProviderAuthorizedCreditCards { get; set; }
        public DbSet<AuthorizedCreditCard> AuthorizedCreditCards { get; set; }
        public DbSet<ProviderPackage> ProviderPackages { get; set; }

        public DbSet<ProviderEmailPreference> ProviderEmailPreferences { get; set; }
        public DbSet<EmailType> EmailTypes { get; set; }

        public DbSet<RetailSaleReturn> RetailSaleReturns { get; set; }
        public DbSet<ServiceRefund> ServiceRefunds { get; set; }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:18:52+00:00Added an answer on June 15, 2026 at 7:18 pm

    problem is DbContext Derived class’s (DataCatalog) parameter less constructor connection string issue.

    With support of @Pawel I have sorted out my problem.
    You just need to give connection string for parameter less constructor as below.

     public class DataCatalog : DbContext
        {
            public static string ConnectionString { get; set; }
    
            public DataCatalog() : base(ConnectionString ?? "PawLoyalty")
            {
    
            }  
        }
    

    Note 1 : If you’re in separate layer (class library project) then you have to give your connection string on App.Config file.

    Note 2 : After doing all the changes you have to compile your project before run T4 template again

    Hope this will help some one in future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are going to create Jar Store the way like App Store works, but
I can create database manually by going to cpanel. But I'd like to create
using the code DataViewModel with one form for create and edit with partial view
I am using this plugin to create charts: http://www.filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/ The code works below if
As the title says... I'm creating a template purely from code, ie without using
I need to create a WPF grid dynamically from code behind. This is going
so here's what's going on. I have a table that is created in code-behind
I really can't work out what's going on here. I'm using the jQuery load()
I'm using Symfony2 and CraueFormFlowBundle to create a multi-step form. Everything is going well
I am going to create a web site or you may call it a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.