ScriptKidding
ScriptKidding
CC#
Created by ScriptKidding on 4/5/2024 in #help
Render Razor template for email body but keep having errors
question, so i am planning to do some email sending in C# but the body will be some nifty HTML and CSS styling with extra data in it, so should i create a Razor file then render it in ? or is there a better option ? because currently i am trying out Razor and this line keeps failing me
string body= Engine.Razor.RunCompile(this.templatePath, null, MyOwnDictionaryObject);
string body= Engine.Razor.RunCompile(this.templatePath, null, MyOwnDictionaryObject);
Error :
System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
and not so sure what that means
1 replies
CC#
Created by ScriptKidding on 3/24/2024 in #help
✅ Error while Dockerizing an ASP.NET project which references another project.
No description
13 replies
CC#
Created by ScriptKidding on 3/19/2024 in #help
Unable to add migration -
So i am having a working ASP.NET application running .NET 8.0. At first everything runs normally but when i try to add some migrations with the Add-Migration command, an error pop up as follows:
PM> Add-Migration InitialCreate
Build started...
Build succeeded.
Unable to create a 'DbContext' of type ''. The exception 'Cannot use table 'SyllabusTrainingProgram' for entity type 'SyllabusTrainingProgram (Dictionary<string, object>)' since it is being used for entity type 'SyllabusTrainingProgram' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'SyllabusTrainingProgram (Dictionary<string, object>)' on the primary key properties and pointing to the primary key on another entity type mapped to 'SyllabusTrainingProgram'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
PM>
PM> Add-Migration InitialCreate
Build started...
Build succeeded.
Unable to create a 'DbContext' of type ''. The exception 'Cannot use table 'SyllabusTrainingProgram' for entity type 'SyllabusTrainingProgram (Dictionary<string, object>)' since it is being used for entity type 'SyllabusTrainingProgram' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'SyllabusTrainingProgram (Dictionary<string, object>)' on the primary key properties and pointing to the primary key on another entity type mapped to 'SyllabusTrainingProgram'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
PM>
I have already tried to add the following lines of code inside the OnModelCreating method of the DbContext to create a relationship to the child models...
// Other pre-scaffoled code

modelBuilder.Entity<SyllabusTrainingProgram>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__SysTrainC__3213E83F0F533B87");

entity.HasOne(d => d.syllabus).WithMany(p => p.SyllabusTrainingPrograms)
.HasPrincipalKey(p => p.SyllabusId)
.HasForeignKey(d => d.SyllabusId)
.HasConstraintName("FK_SyllabusTrainingProgram_Syllabus");

entity.HasOne(d => d.program).WithMany(p => p.SyllabusTrainingPrograms)
.HasPrincipalKey(p => p.TrainingProgramCode)
.HasForeignKey(d => d.TrainingProgramCode)
.HasConstraintName("FK_SyllabusTrainingProgram_Program");
});

OnModelCreatingPartial(modelBuilder);
// Other pre-scaffoled code

modelBuilder.Entity<SyllabusTrainingProgram>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK__SysTrainC__3213E83F0F533B87");

entity.HasOne(d => d.syllabus).WithMany(p => p.SyllabusTrainingPrograms)
.HasPrincipalKey(p => p.SyllabusId)
.HasForeignKey(d => d.SyllabusId)
.HasConstraintName("FK_SyllabusTrainingProgram_Syllabus");

entity.HasOne(d => d.program).WithMany(p => p.SyllabusTrainingPrograms)
.HasPrincipalKey(p => p.TrainingProgramCode)
.HasForeignKey(d => d.TrainingProgramCode)
.HasConstraintName("FK_SyllabusTrainingProgram_Program");
});

OnModelCreatingPartial(modelBuilder);
but no use. Since the code are too long, i have already put it here https://bpa.st/GB7A which contains the code of the entities that i doubt caused this problem. I'd appreciate if someone help me out.
1 replies