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

.NET (Core and Framework)

 
GeneralRe: Column length change using Entity Framework Code First Pin
simpledeveloper18-Mar-20 3:14
simpledeveloper18-Mar-20 3:14 
GeneralRe: Column length change using Entity Framework Code First Pin
Richard Deeming18-Mar-20 3:55
mveRichard Deeming18-Mar-20 3:55 
GeneralRe: Column length change using Entity Framework Code First Pin
simpledeveloper18-Mar-20 8:43
simpledeveloper18-Mar-20 8:43 
GeneralRe: Column length change using Entity Framework Code First Pin
Richard Deeming18-Mar-20 8:48
mveRichard Deeming18-Mar-20 8:48 
GeneralRe: Column length change using Entity Framework Code First Pin
simpledeveloper19-Mar-20 5:54
simpledeveloper19-Mar-20 5:54 
Questionc# forms (holy crap i'm not ready for this) Pin
Uranium-23513-Mar-20 23:51
Uranium-23513-Mar-20 23:51 
AnswerRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan14-Mar-20 1:07
mveRichard MacCutchan14-Mar-20 1:07 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23514-Mar-20 4:37
Uranium-23514-Mar-20 4:37 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Dave Kreskowiak14-Mar-20 4:58
mveDave Kreskowiak14-Mar-20 4:58 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23514-Mar-20 5:35
Uranium-23514-Mar-20 5:35 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Dave Kreskowiak14-Mar-20 6:30
mveDave Kreskowiak14-Mar-20 6:30 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan14-Mar-20 6:11
mveRichard MacCutchan14-Mar-20 6:11 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23514-Mar-20 6:51
Uranium-23514-Mar-20 6:51 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan14-Mar-20 7:02
mveRichard MacCutchan14-Mar-20 7:02 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23514-Mar-20 20:42
Uranium-23514-Mar-20 20:42 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Uranium-23514-Mar-20 20:25
Uranium-23514-Mar-20 20:25 
GeneralRe: c# forms (holy crap i'm not ready for this) Pin
Richard MacCutchan14-Mar-20 22:10
mveRichard MacCutchan14-Mar-20 22:10 
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.

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.