简体   繁体   中英

Error executing query: Telerik.OpenAccess.RT.sql.SQLException: Invalid object name 'Employee'

I am using Telerik Open Access ORM in my asp.net C# web application. In my app, I have mapped a table entity from database named "Person" as base class and created a Sub Domain Class named "Employee" . Then I have applied vertical inheritance for subclass to the Base class and used "Default mapping" for the Employee Sub class.

While querying both Base/Sub class I am getting error :

Error executing query: Telerik.OpenAccess.RT.sql.SQLException: Invalid object name 'Employee'.

These are the lines added to query from the context:

       using (EntitiesModel1 obj = new EntitiesModel1())
        {
            List<Employee> lstEmp = obj.Employees.ToList();
          GridView1.DataSource = lstEmp;
          GridView1.DataBind();
        }

Please help.

When you specify the Inheritance strategy to be 'Vertical' this implies that each class has it's own physical table. Hence you get the error that 'Employee' table is missing.

If you want to store instances of both Person and Employee in a single table 'Person', you need to use the default Inheritance strategy, which is 'Flat'.

In case you want to create the additional 'Employee' table then you can use the Schema Handler API and let OpenAccess generate the apporpriate ddl.

var context = new EntityDiagram();
var schemaHandler = context.GetSchemaHandler();
var ddl = schemaHandler.CreateUpdateDDLScript(null);
if(string.IsNullOrEmpty(ddl) == false)
   schemaHandler.ExecuteDDLScript(ddl);

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