Groups > Asp .Net > Data Access and ObjectDataSource Control > DataBounding Control combing with LinqDataSource .... Inheritance class problem !!




DataBounding Control combing with LinqDataSource ....
Inheritance class problem !!

DataBounding Control combing with LinqDataSource .... Inheritance class problem !!
Thu, 3 Apr 2008 10:46:27 +0000
I find few people discuss LinqDataSource ...  Now I propose a question , please
see example:

 I use the inheritance model suggested by official LINQ team in the VS2008 ORM
tools.

I have a base class  Person , and two derived class : Manager , Worker;

Acutually just Person is generated by realy table in Datatable; And Manager ,
Worker 

 

Original   Person Table:

ID:        common

Name:   common

Age:      common

Title:      Manager field

Tool:      Worker field

Type:     ( sub class discriminator ) 

 

Then I drag the Person table to design panel and system generates the base
Person class , which holds just ID, Name, Age and Type fields;

Then I manually create a Manager class ( holds Title , when Person's Type=1 ) ,
a Worker class( holds tool , when Person's Type = 2 ) , letting them inherits
the Person class; 

 

 

Then in the generated db class , only the Person class is "perfectly" 
set ; I can operate such class entities in LinqDataSource ( assign
"TableName" as "Person" then everything becomes easy ); 
however , if I want  deal with Manager object, or Worker, troubles pour out !
Firstly I cannot simply assign a LinqDataSource's TableName with
"Manager" ---- framework cannot directly retrieve such kind of class (
want not to mention db.Persons.OfType<Manager>() )  ,  the Insert  ,
Update operations over Manager are also impossible , for that They are not as
"concrete" as Person when touching database access.   Using
db.GetTable<Manager>() cause a retrieving failure exception.

 

Still in this case , If  I want to make an association between Manager and
Worker , that is : a manager can manage several workers; I cannot correctly
point the "Worker" class to "Manager" to form such a tier ,
for that in the orm environment each association needs at least a
"field" from "parent class" and a field from "child
class" , while both  Manager's key field and Workers key field are Person's
"ID" ,  so what I could do is just hooking  the Person to itself to
represent its children -- Manager and Worker 's relationship  ---- it looks
absurdly ,  but in current VS ORM version I find no better solution to solve
such case.  

 

Experts , who can tell me how to improve the model ??  Thanks !! And I beg
Microsoft LINQ team to enhence the whole development system in the near furture
!!
Post Reply
about | contact