developer tip

ADO.NET Entity Framework : 업데이트 마법사가 테이블을 추가하지 않습니다.

optionbox 2020. 9. 8. 07:54
반응형

ADO.NET Entity Framework : 업데이트 마법사가 테이블을 추가하지 않습니다.


나는 새로운 ADO.Net 엔터티 데이터 모델을 추가 내 프로젝트에와 사용 업데이트 마법사를 모델로 테이블을 추가 할 수 있습니다. 선택한 테이블 중 5 개가 디자인 화면에 추가되었습니다. 다른 두 테이블은 추가되지 않습니다. 마법사에서 선택하고 마침을 클릭했지만 디자인 화면에는 나타나지 않습니다.

이것은 버그입니까, 아니면 테이블을 모델에 추가 할 수없는 상황이 있습니까 (설계 상)?


업데이트 : XML (*. edmx)이 문제를 보여줍니다.

<!--Errors Found During Generation:
warning 6013: The table/view 'FooBar.dbo.Roles' does not 
have a primary key defined and no valid primary key could be inferred. 
This table/view has been excluded. To use the entity you will need to 
review your schema, add the correct keys and uncomment it.-->
<!--<EntityType Name="Roles">
    <Property Name="role_id" Type="decimal" />
    <Property Name="role_desc" Type="nvarchar" MaxLength="30" />
</EntityType>-->

디자인 화면은 엔터티 모델과 다릅니다. 디자인 화면에 나타나지 않는 EDMX의 매핑에 테이블이있을 수 있습니다. 파일을 XML로보고이 경우인지 확인하십시오. 이 경우 테이블이 이미 엔터티 모델의 일부이므로 업데이트 마법사를 사용하여 테이블을 다시 추가 할 수 없습니다. 따라서 일반적으로 업데이트 마법사는 디자인 화면 자체 보다 엔터티 모델에 대해 더 많이 알고 있습니다 .

나는 그것이 당신이 처한 상황과 정확히 일치한다고 생각하지 않지만 솔루션에 대한 일반적인 아이디어를 제공해야합니다. XML로 가서 문제의 테이블에 대한 참조를 찾으십시오.


모든 테이블에 기본 키를 설정하거나 각 테이블의 모든 열에 하나의 선택되지 않은 확인란 "널 허용"을 설정합니다. 그것은 나를 위해 작동합니다 :)


1. 테이블 구조를 변경하고 기본 열을 추가합니다. 모델을 업데이트하십시오.

2. XML 편집기에서 .EDMX 파일을 수정하고이 특정 테이블의 태그 아래에 새 열을 추가해보십시오. (작동 안 할 것이다)

3. Exiting 테이블에 대한 새로운 Primary Column을 생성하는 대신 기존의 모든 컬럼을 포함하여 복합 키를 생성합니다.

Entity Framework : 기본 키가없는 DataTable을 엔터티 모델에 추가합니다.


나도이 문제가 있었고 위의 모든 것이 저에게 효과가 없었습니다. 저에게 도움이 된 것은 다음과 같습니다.

데이터베이스에 연결하려고하면 해당 데이터베이스는 다른 자격 증명을 가진 다른 사용자를 가질 수 있습니다. 사용자 A가 D까지라고 가정하겠습니다.

사용자와 연결을 시도하는 경우 사용자에게 올바른 자격 증명이 활성화되어 있는지 확인하십시오.이 경우 읽기 및 쓰기 옵션이 활성화되어 있습니다.

이렇게하려면 SQL 서버에 연결된 MS SQL Server Managment Studio를 시작하고 Visual Studio에서 연결하려는 데이터베이스를 선택합니다. 'your_dbname'-> 보안-> 사용자 아래에 사용자 목록이 있습니다. 로그인하려는 사용자 이름을 마우스 오른쪽 버튼으로 클릭하고 속성을 선택합니다. 창이 열립니다. '일반'(기본적으로 선택됨) 페이지를 선택하고 '데이터베이스 역할 멤버십'탭에서 'db_datareader'및 'db_datawrite'가 선택되었는지 확인합니다.

참고 : MS SQL Server Managment Studio에 너무 로그인 할 때 이러한 옵션을 활성화 / 비활성화 할 수있는 사용자로 로그인해야합니다.


Check for 'Nulls' in your particular table. If all the columns are set to 'Allow Null' Entity Framework considers it as a 'Null' table. I had the same problem and unchecked 'Allow Null' and it added the required table.


Tables without primary keys will not be added.


My solution to this is to delete the entire model and readd it including the new tables that I want.

I accidentally deleted a table in the designer once and could not readd it. Hence removing entire model and readding it.

I had some issues with this as well (Ado.Net Entity Data Model Not Updating Correctly)


This has been resolved in latest version(environment: VS 2012 , .net framework 4.5). Simple open the .edmx file and add the required tables / stored procedures / views. The table/view which doesnt have primary key will be created as read only table/view.

The table/view 'TABLE_NAME' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.


You do not need to delete the entire model (that might be hundreds of tables!).

The Wizard can handle "adding new" items, but some changes such as changing composite keys and renaming columns - it doesn't know what to do - so it doesn't try - and things get out of sync.

SO: DELETE the tables in question from the Model (conceptual mode) AND from the Model.Store, and then Update the model using the Wizard, and re-add just the tables in question.


Just throwing out some more detail for anybody who has not had to do this before. I am using visual studio 2013 with update 4 installed. I added some fields to a table, deleted the table from my model then went to update and it would not let me check any of the tables.

I do have a primary key.

I created a new test table, that showed up and it would let me check it but not my original.

I have never opened it in XML before and did not know how to do that. You right click on the .edmx file and "open with" -- choose the xml editor.

the table in question was there all right, it even had the new fields (strange).

I deleted all the references to it (took a couple times) -- after you delete one and save, if you try to open it and it won't display just go ahead and choose "view XML" - look at the errors and basically follow the bouncing ball until you have cleaned it up.

hope the extra detail helps somebody.

Joe


One easy way I found was to (in SQL Server Management Studio) add an ID column of type INT, deselect "Allow Nulls", and under Column properties (of ID) >> Identity Specification >> check (Is Identity), and make sure increment is set.

Once the above is done, go back to your .edmx window, right-click, and Update Model from Database.

참고URL : https://stackoverflow.com/questions/543971/ado-net-entity-framework-update-wizard-will-not-add-tables

반응형