简体   繁体   中英

Entity Framework Invalid Object Name Error

I'm using VS2008 to connect to a SQL server database in order to populate it in C#. It's going pretty well, I'm able to query, insert, and update all tables in my database successfully, except one. Anytime I try to query or insert into one table I get the following error:

Message = "Invalid object name 'DB_NewModelStoreContainer.DATATYPE'."

the query that generated this error is:

var test3 = (from o in context.DATATYPE
where o.DATETYPE_NAME == "Single"
select o).First();
(yes I know it should be DATATYPE, but that is not the problem =) )

Whenever I added the database to my project, for some reason it marked every attribute in the DATATYPE table as a primary key. I went into the xml of the .edmx and fixed this but I still get this error and I cannot find out why ><. Any help at all would be very greatly appreciated! Thanks in advance.

In order to work with EntityFramework ,there should be clearly mentioned PrimaryKey and Foreign Key if any exists.

If you don't have any primary Key ,make the unique column as primary key ,It should definately work. and I am wondering how could you are able to insert record without primary key

in edmx designer you might have misssed something or may be some mapping got screwed up after changes.so,modify the tables in your database to asign the primary key to every table and then try to generate the edmx from scratch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM