none
Getting an error 3024: "problem in mapping fragments" and "Must specify mapping for all key properties" in an entity set RRS feed

  • Question

  • I've got situation in which I'm saving some data to a table. Very simple table definition:

    CREATE TABLE [ASICheckOut](
    	[ClientNumber] [int] NOT NULL,
    	[CaseNumber] [tinyint] NOT NULL,
    	[Followup] [tinyint] NOT NULL,
    	[LogonID] [varchar](15) NOT NULL,
    	[CheckOutDate] [datetime] NOT NULL,
    	[ClientFirstName] [varchar](20) NOT NULL,
    	[ClientLastName] [varchar](25) NOT NULL,
    	[ExplicitCheckOut] [bit] NOT NULL,
    	[MachineName] [varchar](30) NULL,
    	[DateSavedToBackendDB] [datetime] NULL,
     CONSTRAINT [PK_ASICheckOut] PRIMARY KEY NONCLUSTERED 
    (
    	[ClientNumber] ASC,
    	[CaseNumber] ASC,
    	[Followup] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    
    And I'm not sure at this point, but the next table is a part of the error message, so it's definition follows:
      CREATE TABLE [UserOptions](
    	[LoginID] [varchar](15) NOT NULL,
    	[DaysToRetainAssessments] [smallint] NOT NULL,
     CONSTRAINT [PK_UserOptions] PRIMARY KEY CLUSTERED 
    (
    	[LoginID] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    

    In my entity framework model I'm just trying to do an insert into ASICheckOut. Not rocket science. But I'm getting the following error message:

    System.Exception was caught
      HResult=-2146233088
      Message=Error saving ASICheckOut record to local database: Error retrieving values from ObjectStateEntry. See inner exception for details.;Inner Exception:
    AsiModel.msl(1344,10) : error 3024: Problem in mapping fragments starting at line 1344:Must specify mapping for all key properties (UserOptions.LogonID, UserOptions.LoginID) of the EntitySet UserOptions.


    Rod

    Thursday, January 31, 2013 10:24 PM

Answers

  • The fist time you do any query against the model one of the things that EF does is validate that the model is correct and attempt to generate views that it can use to persist and retrieve all the data. This is then cached so it doesn't happen a second time in the app domain.

    The reason you are getting an error about UserOptions when you are inserting an ASICheckout is probably because the insert is triggering that validation, and it's failing.

    As to the error message, it seems to be telling you that the mapping of UserOptions is wrong. Does it appear to be mapped correctly on the designer?


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    • Marked as answer by Rod at Work Tuesday, February 5, 2013 7:47 PM
    Friday, February 1, 2013 6:28 PM
    Moderator

All replies

  • Hi Rod,

    Welcome to the MSDN forum.

    Did you use Database First approach?

    Please open edmx and check whether or not UserOptions.LogonID and UserOptions.LoginID are mapped correctly in UserOptions EntitySet. Please refer to this page: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/470c7ffb-7ec9-4c6b-8912-667b47675e62

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 1, 2013 8:40 AM
  • Hi Alexander,

    You are correct, I did do Database First approach. The database is over 10 years old, so it was the appropriate way to go.

    Now, as far as I can see, when I look at the mapping details of the UserOptions table (it's called UserOption by EF) there isn't an association between the UserOptions table and the ASICheckOut table, and that's the way it is in the database. But now that I've got the EF designer open and am looking at the UserOption entity, there is something odd about it. It has a property there called LogonID, which as you can see from the DDL I specified yesterday, isn't in the UserOptions table. Why did it do that? I was using EF 4.2.

    I'm going to remove LogonID and see what happens.


    Rod

    Friday, February 1, 2013 4:39 PM
  • The fist time you do any query against the model one of the things that EF does is validate that the model is correct and attempt to generate views that it can use to persist and retrieve all the data. This is then cached so it doesn't happen a second time in the app domain.

    The reason you are getting an error about UserOptions when you are inserting an ASICheckout is probably because the insert is triggering that validation, and it's failing.

    As to the error message, it seems to be telling you that the mapping of UserOptions is wrong. Does it appear to be mapped correctly on the designer?


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    • Marked as answer by Rod at Work Tuesday, February 5, 2013 7:47 PM
    Friday, February 1, 2013 6:28 PM
    Moderator
  • It was not mapped correctly in the designer. I found that it had an additional field in it, which wasn't in the table in SQL Server. I've no idea why it had that field. I deleted the field in the designer, and then it started working fine.

    Rod

    Tuesday, February 5, 2013 7:47 PM