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 6579701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:55:52+00:00 2026-05-25T15:55:52+00:00

I know the question already has a solution (eg. this question ) but I

  • 0

I know the question already has a solution (eg. this question) but I really can’t afford to attach the mapping logic in the same assembly where the domain (POCO classes) is.

Is there any other way?

I found this nice blog post but I couldn’t get it working.
Here is the model:

public class Institute
{
    /**
        Code omitted
    **/

    protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; }

    private InstituteTextSet _TextSets;

    public InstituteTextSet Texts 
    {
        get 
        {
            if (_TextSets == null)
                _TextSets = new InstituteTextSet(InnerInstituteTexts);

            return _TextSets;
        }
    }
}

Mapping code:

var instituteTextExpression = ObjectAccessor<Institute>.CreateExpression<ICollection<InstituteText>>("InnerInstituteTexts");

institute.HasMany(instituteTextExpression)
    .WithRequired()
    .HasForeignKey(t => t.InstituteId);

where CreateExpression is defined as:

public static Expression<Func<T, TResult>> CreateExpression<TResult>(string propertyOrFieldName)
{
    ParameterExpression param = Expression.Parameter(typeof(T), "propertyOrFieldContainer");
    Expression body = Expression.PropertyOrField(param, propertyOrFieldName);
    LambdaExpression lambda = Expression.Lambda(typeof(Func<T, TResult>), body, param);

    return (Expression<Func<T, TResult>>) lambda;
}

the error I get is:

Initialization method
Studentum.Core.Tests.InstituteTests.Initialize
threw exception.
System.TypeInitializationException:
System.TypeInitializationException:
The type initializer for
‘Studentum.Core.FluentCoreRepositoryFactory’
threw an exception. —>
System.InvalidOperationException: The
configured property
‘InnerInstituteTexts’ is not a
declared property on the entity
‘Institute’. Verify that it has not
been explicitly excluded from the
model and that it is a valid primitive
property..

  • 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-05-25T15:55:52+00:00Added an answer on May 25, 2026 at 3:55 pm

    The first thing that came to mind is the InternalsVisibleTo assembly attribute. This allows you to name “friend” assemblies that also have access to internal members. I wasn’t sure if this would work with EF CodeFirst, but I tried it and it appears to work just fine. You would have to change your model assembly slightly, but I think it is a reasonable change.

    You would first need to change your property declaration to protected internal:

     protected internal virtual ICollection<InstituteText> InnerInstituteTexts { get; set; }
    

    Then, in your model assembly, add the InternalsVisibleTo assembly attribute in your AssemblyInfo.cs file with the name of your mapping assembly.

    [assembly: InternalsVisibleTo("MappingAssemblyName")]
    

    Finally, you can define your mapping of the property in the mapping assembly like any other publicly accessible property.

    institute.HasMany(i => i.InnerInstituteTexts)
        .WithRequired()
        .HasForeignKey(t => t.InstituteId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has already been asked, but the solution doesn't work in
I know a question like this was already asked, but the situation is a
I know there is already a question about this but my issue is more
There's already a question on this here. But i want to know if its
i know this question has been asked here but i am stuck with this
Apologies if this question has already been asked but I do not think I
I know this flavor of question has been asked multiple times, but I've spent
I saw a post on this already, but it didn't really provide a solution
I know that this may seem as a question that was already asked, but
I already know the obvious answer to this question: just download <insert favorite windows

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.