Click here to Skip to main content
15,868,014 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23515-Mar-20 4:41
Uranium-23515-Mar-20 4:41 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan15-Mar-20 4:44
mveRichard MacCutchan15-Mar-20 4:44 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23515-Mar-20 7:40
Uranium-23515-Mar-20 7:40 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan15-Mar-20 8:00
mveRichard MacCutchan15-Mar-20 8:00 
AnswerRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-2359-Apr-20 23:01
Uranium-2359-Apr-20 23:01 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23510-Apr-20 10:12
Uranium-23510-Apr-20 10:12 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23511-Apr-20 16:33
Uranium-23511-Apr-20 16:33 
QuestionEntity Framework Code First is generating an extra column - need some help please Pin
simpledeveloper9-Mar-20 9:44
simpledeveloper9-Mar-20 9:44 
Hi I am using Entity Framework Code First to gnerate a table, its generating table correctly, but when I am querying it seems like its generating or asking for an extra column, which I didn't intend for.

Here is my Code First Entity Class
[Table("CaseAssignedToInvestigators")]
public class CaseAssignedToInvestigator
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int CaseAssignedToInvestigatorsId { get; set; }

    [Required]
    [Index("IX_UniqueConstraintCaseAssignedToInvestigator", 1, IsUnique = true)]
    public int CaseId { get; set; }
    public Case Case { get; set; }

    [Required]
    [Index("IX_UniqueConstraintCaseAssignedToInvestigator", 2, IsUnique = true)]
    [MaxLength (128)]
    public string UserId { get; set; }
    public ApplicationUser ApplicationUser { get; set; }
}

Its generating table properly, but when I queruing as below:
public IQueryable<T> GetAll()
{
    return this.DbSet.AsQueryable();
}

This is generating a query with a column which doesn't exist, as below:
SELECT 
    [Extent1].[CaseAssignedToInvestigatorsId] AS [CaseAssignedToInvestigatorsId], 
    [Extent1].[CaseId] AS [CaseId], 
    [Extent1].[UserId] AS [UserId], 
    [Extent1].[ApplicationUser_Id] AS [ApplicationUser_Id]
    FROM [dbo].[CaseAssignedToInvestigators] AS [Extent1]

Here [ApplicationUser_Id] is not a column I am intending for, how can I get rid of this, my migration script had it but I commented it out, any help please thanks in advance.
My migration file is as below:
public partial class CaseAssignedToInvestigator_AddPK : DbMigration
{
    public override void Up()
    {
        //DropForeignKey("dbo.CaseAssignedToInvestigators", "CaseId", "dbo.Cases");
        //DropForeignKey("dbo.CaseAssignedToInvestigators", "UserId", "dbo.AspNetUsers");
        //DropIndex("dbo.CaseAssignedToInvestigators", new[] { "CaseId" });
        //DropIndex("dbo.CaseAssignedToInvestigators", new[] { "UserId" });
        CreateTable(
            "dbo.CaseAssignedToInvestigators",
            c => new
            {
                CaseAssignedToInvestigatorsId = c.Int(nullable: false, identity: true),
                CaseId = c.Int(nullable: false),
                UserId = c.String(nullable: false, maxLength: 128)
            })
            .PrimaryKey(t => t.CaseAssignedToInvestigatorsId)
            .ForeignKey("dbo.AspNetUsers", t => t.UserId)
            .ForeignKey("dbo.Cases", t => t.CaseId, cascadeDelete: true)
            .Index(t => new { t.CaseId, t.UserId }, unique: true, name: "IX_UniqueConstraintCaseAssignedToInvestigator");
            //.Index(t => t.UserId);

        //AddColumn("dbo.AspNetUsers", "Case_CaseId", c => c.Int());
        //CreateIndex("dbo.AspNetUsers", "Case_CaseId");
        //AddForeignKey("dbo.AspNetUsers", "Case_CaseId", "dbo.Cases", "CaseId");
        //DropTable("dbo.CaseAssignedToInvestigators");
    }

    public override void Down()
    {
        CreateTable(
            "dbo.CaseAssignedToInvestigators",
            c => new
                {
                    CaseId = c.Int(nullable: false),
                    UserId = c.String(nullable: false, maxLength: 128),
                })
            .PrimaryKey(t => new { t.CaseId, t.UserId });

        DropForeignKey("dbo.CaseAssignedToInvestigators", "CaseId", "dbo.Cases");
        //DropForeignKey("dbo.CaseAssignedToInvestigators", "ApplicationUser_Id", "dbo.AspNetUsers");
        DropForeignKey("dbo.AspNetUsers", "Case_CaseId", "dbo.Cases");
        //DropIndex("dbo.CaseAssignedToInvestigators", new[] { "ApplicationUser_Id" });
        DropIndex("dbo.CaseAssignedToInvestigators", "IX_UniqueConstraintCaseAssignedToInvestigator");
        DropIndex("dbo.AspNetUsers", new[] { "Case_CaseId" });
        DropColumn("dbo.AspNetUsers", "Case_CaseId");
        DropTable("dbo.CaseAssignedToInvestigators");
        CreateIndex("dbo.CaseAssignedToInvestigators", "UserId");
        CreateIndex("dbo.CaseAssignedToInvestigators", "CaseId");
        AddForeignKey("dbo.CaseAssignedToInvestigators", "UserId", "dbo.AspNetUsers", "Id", cascadeDelete: true);
        AddForeignKey("dbo.CaseAssignedToInvestigators", "CaseId", "dbo.Cases", "CaseId", cascadeDelete: true);
    }
}

All the commented out code in my migration script is not needed for me - any help would be much appreciated thanks in advance.
AnswerRe: Entity Framework Code First is generating an extra column - need some help please Pin
Uranium-2359-Mar-20 14:13
Uranium-2359-Mar-20 14:13 
AnswerRe: Entity Framework Code First is generating an extra column - need some help please Pin
Richard Deeming10-Mar-20 0:55
mveRichard Deeming10-Mar-20 0:55 
QuestionBest way to remotely send/retrieve data (securely) Pin
Uranium-2357-Mar-20 15:03
Uranium-2357-Mar-20 15:03 
AnswerRe: Best way to remotely send/retrieve data (securely) Pin
Gerry Schmitz8-Mar-20 10:05
mveGerry Schmitz8-Mar-20 10:05 
GeneralRe: Best way to remotely send/retrieve data (securely) Pin
Uranium-2358-Mar-20 19:41
Uranium-2358-Mar-20 19:41 
QuestionSending email via .net core 3 using Worker Service Pin
ElenaRez25-Feb-20 4:00
ElenaRez25-Feb-20 4:00 
AnswerRe: Sending email via .net core 3 using Worker Service Pin
ZurdoDev25-Feb-20 4:25
professionalZurdoDev25-Feb-20 4:25 
SuggestionRe: Sending email via .net core 3 using Worker Service Pin
Richard MacCutchan25-Feb-20 4:27
mveRichard MacCutchan25-Feb-20 4:27 
SuggestionRe: Sending email via .net core 3 using Worker Service Pin
Richard Deeming25-Feb-20 4:55
mveRichard Deeming25-Feb-20 4:55 
QuestionProblems with EntityFramwork - compatible Framework Database Driver not found?! Pin
ricardo188515-Feb-20 9:33
ricardo188515-Feb-20 9:33 
AnswerRe: Problems with EntityFramwork - compatible Framework Database Driver not found?! Pin
Gerry Schmitz15-Feb-20 9:52
mveGerry Schmitz15-Feb-20 9:52 
QuestionClosing and Disposing Excel Application Process in C# Pin
Pramod_Kumar14-Feb-20 4:26
Pramod_Kumar14-Feb-20 4:26 
AnswerRe: Closing and Disposing Excel Application Process in C# Pin
Richard Deeming4-Feb-20 4:37
mveRichard Deeming4-Feb-20 4:37 
Questionconverting text file data from string to X,Y,Z coordinates Pin
Sher Shah 11-Feb-20 3:32
Sher Shah 11-Feb-20 3:32 
AnswerRe: converting text file data from string to X,Y,Z coordinates Pin
Pete O'Hanlon1-Feb-20 4:10
subeditorPete O'Hanlon1-Feb-20 4:10 
GeneralRe: converting text file data from string to X,Y,Z coordinates Pin
Sher Shah 11-Feb-20 5:11
Sher Shah 11-Feb-20 5:11 
GeneralRe: converting text file data from string to X,Y,Z coordinates Pin
phil.o1-Feb-20 6:28
professionalphil.o1-Feb-20 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.