The FK relationship was not loaded because the type is not available

c# dll entity-framework

Question

We use a dll created with the Entity Framework 4.1 in one of our C# batch tasks. But the batch job also makes use of the EF (same version), and it appears that this is having some issues.

both the batch job's and the dll's.edmx a connection between the filesAgentTransmission and AgentRelationshipCodes table. AgentTransmission has a connection of one to manyAgentRelationshipCodes The PK forAgentTransmission on the serves as an FK fieldAgentRelationshipCodes table.

The code fragment that follows comes from a dll routine. The batch job uses this approach to search for any records on theAgentTransmission table showing the condition ofWaiting (or W ).

namespace Botticelli
{
    public class MonetToMainframe : IMonetToMainframe
    {
        private static TransmitAgents _db;

        public ResponseMessage TransmitWaitingAgents()
        {
            try
            {
                _db = new TransmitAgents();

                //Exception thrown here
                agtTran = _db.AgentTransmission.FirstOrDefault(w => w.RecordStatus.Equals("W"));

The following exception occurs when the final line above is executed.

Schema specified is not valid. Errors: 

The relationship 'MonetModel.FK__AgentRela__AgtTa__3449B6E4' was not loaded because the 
type 'MonetModel.AgentRelationshipCode' is not available.

I've come across this problem message in a few online posts, but I haven't been able to discover a fix. I'm currently stuck trying to find even a search direction.

However, the first thing that strikes me is that the message is referencingMonetModel as the FK relationship's namespace. TheMonetModel The EF makes use of namespace.DbContext it is only employed in batch jobs. TheDbContext class TransmitAgents nonetheless, is a member of theBotticelli which is accessed by the dll namespace.

The FK relationship is defined in both namespaces, as can be seen in the screenshot below (one used by the batch job, one by the dll)

enter image description here

Here are the pertinent classes and fields taken from the batch job EF namespace and the dll namespace, just to be safe.

AgentTransmission DLL

namespace Botticelli
{
    using System;
    using System.Collections.Generic;

    public partial class AgentTransmission
    {
        public AgentTransmission()
        {
            this.AgentRelationshipCodes = new HashSet<AgentRelationshipCodes>();
        }

        //Tons of fields here, edited for readability

        public virtual ICollection<AgentRelationshipCodes> AgentRelationshipCodes { get; set; }
    }
}

AgentRelationshipCodes DLL

namespace Botticelli
{
    using System;
    using System.Collections.Generic;

    public partial class AgentRelationshipCodes
    {
        public System.Guid Id { get; set; }
        public string RelationshipId { get; set; }
        public Nullable<System.DateTime> EffectiveDate { get; set; }
        public System.DateTime LastChangeDate { get; set; }
        public string LastChangeId { get; set; }
        public Nullable<int> AgtTableId { get; set; }

        public virtual AgentTransmission AgentTransmission { get; set; }
    }
}

DbContext DLL

namespace Botticelli
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class TransmitAgents : DbContext
    {
        public TransmitAgents()
            : base("name=TransmitAgents")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<TransmissionHistory> TransmissionHistory { get; set; }
        public DbSet<AgentRelationshipCodes> AgentRelationshipCodes { get; set; }
        public DbSet<AgentTransmission> AgentTransmission { get; set; }
    }
}

Job in Batch: AgentTransmission

namespace LVOAGT
{
    using System;
    using System.Collections.Generic;

    public partial class AgentTransmission
    {
        public AgentTransmission()
        {
            this.AgentRelationshipCodes = new HashSet<AgentRelationshipCode>();
        }

        //Tons of fields here, edited for readability

        public virtual ICollection<AgentRelationshipCode> AgentRelationshipCodes { get; set; }
    }
}

AgentRelationshipCodes Batch Job

namespace LVOAGT
{
    using System;
    using System.Collections.Generic;

    public partial class AgentRelationshipCode
    {
        public System.Guid Id { get; set; }
        public string RelationshipId { get; set; }
        public Nullable<System.DateTime> EffectiveDate { get; set; }
        public System.DateTime LastChangeDate { get; set; }
        public string LastChangeId { get; set; }
        public Nullable<int> AgtTableId { get; set; }

        public virtual AgentTransmission AgentTransmission { get; set; }
    }
}

DbContext for a Batch Job

namespace LVOAGT
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class MonetDb : DbContext
    {
        public MonetDb()
            : base("name=MonetDb")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<BatchDashboard> BatchDashboard { get; set; }
        public DbSet<TransmissionHistory> TransmissionHistories { get; set; }
        public DbSet<ConfigStuff> ConfigStuffs { get; set; }
        public DbSet<AgentRelationshipCode> AgentRelationshipCodes { get; set; }
        public DbSet<AgentTransmission> AgentTransmissions { get; set; }
    }
}
1
1
6/2/2014 8:33:22 PM

Accepted Answer

After creating a new table called "oepost" and creating a foreign key relationship with another table called "category," I ran the custom tool by right-clicking the edmx file. I encountered the following problem while executing the application. By incorporating post table foreign key relationships to the category class, it was fixed.

 public Category()
    {
        this.Posts = new HashSet<Post>();

    }
 public virtual ICollection<Post> Posts { get; set; }

I've included the model class category. for more information: http://www.infinetsoft.com/Post/-Solved-The-relationship-model-was-not-loaded-because-the-type-model-is-not-available/1244

1
5/25/2016 2:29:27 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow