Class with DataAnnotation [Table(“Tablename”)] inherit by another class with variable get set not...
up vote
0
down vote
favorite
Working with a class:
DBContext:
public SDBContext() : base("name=SPDBContext")
{
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Table1> table_1 { get; set; }
A Class with Annotation:
[Table("table_1")]
public abstract class Table1
{
public int id { get; set; }
public string name { get; set; }
public DateTime? dt { get; set; }
}
A normal Class to inherit the class above:
public class InheritTable1 : Table1
{
public String Address { get; set; }
public static DataTable GetTable1()
{
try
{
DataTable dt = new DataTable();
SDBContext sdb = new SDBContext();
var getData = sdb.table_1.ToList();
dt.Merge(CollecTables.ToDataTable(getData));
return dt;
}
catch (Exception er)
{
throw er;
}
}
}
Implementation:
dataGridView1.DataSource = InheritTable1.GetTable1();
If i remove this section of code:
public String Address { get; set; }
It is working well.
But if i run that code with public String Address { get; set; }
It returns an error:
Message = "Unknown column 'Extent1.Address' in 'field list'"
I knew this Extent1
means reading from Table1 Class
. why it is treated as Table1
instead of InheritTable1
.
All that i knew is:
A class that inherit an Abstract Class can Add a method anytime we wanted but my question is:
why it can't be done with it's own variable (with this class InheritTable1
)?
c# mysql entity-framework data-annotations
add a comment |
up vote
0
down vote
favorite
Working with a class:
DBContext:
public SDBContext() : base("name=SPDBContext")
{
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Table1> table_1 { get; set; }
A Class with Annotation:
[Table("table_1")]
public abstract class Table1
{
public int id { get; set; }
public string name { get; set; }
public DateTime? dt { get; set; }
}
A normal Class to inherit the class above:
public class InheritTable1 : Table1
{
public String Address { get; set; }
public static DataTable GetTable1()
{
try
{
DataTable dt = new DataTable();
SDBContext sdb = new SDBContext();
var getData = sdb.table_1.ToList();
dt.Merge(CollecTables.ToDataTable(getData));
return dt;
}
catch (Exception er)
{
throw er;
}
}
}
Implementation:
dataGridView1.DataSource = InheritTable1.GetTable1();
If i remove this section of code:
public String Address { get; set; }
It is working well.
But if i run that code with public String Address { get; set; }
It returns an error:
Message = "Unknown column 'Extent1.Address' in 'field list'"
I knew this Extent1
means reading from Table1 Class
. why it is treated as Table1
instead of InheritTable1
.
All that i knew is:
A class that inherit an Abstract Class can Add a method anytime we wanted but my question is:
why it can't be done with it's own variable (with this class InheritTable1
)?
c# mysql entity-framework data-annotations
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Working with a class:
DBContext:
public SDBContext() : base("name=SPDBContext")
{
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Table1> table_1 { get; set; }
A Class with Annotation:
[Table("table_1")]
public abstract class Table1
{
public int id { get; set; }
public string name { get; set; }
public DateTime? dt { get; set; }
}
A normal Class to inherit the class above:
public class InheritTable1 : Table1
{
public String Address { get; set; }
public static DataTable GetTable1()
{
try
{
DataTable dt = new DataTable();
SDBContext sdb = new SDBContext();
var getData = sdb.table_1.ToList();
dt.Merge(CollecTables.ToDataTable(getData));
return dt;
}
catch (Exception er)
{
throw er;
}
}
}
Implementation:
dataGridView1.DataSource = InheritTable1.GetTable1();
If i remove this section of code:
public String Address { get; set; }
It is working well.
But if i run that code with public String Address { get; set; }
It returns an error:
Message = "Unknown column 'Extent1.Address' in 'field list'"
I knew this Extent1
means reading from Table1 Class
. why it is treated as Table1
instead of InheritTable1
.
All that i knew is:
A class that inherit an Abstract Class can Add a method anytime we wanted but my question is:
why it can't be done with it's own variable (with this class InheritTable1
)?
c# mysql entity-framework data-annotations
Working with a class:
DBContext:
public SDBContext() : base("name=SPDBContext")
{
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Table1> table_1 { get; set; }
A Class with Annotation:
[Table("table_1")]
public abstract class Table1
{
public int id { get; set; }
public string name { get; set; }
public DateTime? dt { get; set; }
}
A normal Class to inherit the class above:
public class InheritTable1 : Table1
{
public String Address { get; set; }
public static DataTable GetTable1()
{
try
{
DataTable dt = new DataTable();
SDBContext sdb = new SDBContext();
var getData = sdb.table_1.ToList();
dt.Merge(CollecTables.ToDataTable(getData));
return dt;
}
catch (Exception er)
{
throw er;
}
}
}
Implementation:
dataGridView1.DataSource = InheritTable1.GetTable1();
If i remove this section of code:
public String Address { get; set; }
It is working well.
But if i run that code with public String Address { get; set; }
It returns an error:
Message = "Unknown column 'Extent1.Address' in 'field list'"
I knew this Extent1
means reading from Table1 Class
. why it is treated as Table1
instead of InheritTable1
.
All that i knew is:
A class that inherit an Abstract Class can Add a method anytime we wanted but my question is:
why it can't be done with it's own variable (with this class InheritTable1
)?
c# mysql entity-framework data-annotations
c# mysql entity-framework data-annotations
edited Nov 21 at 2:20
asked Nov 21 at 1:57
Vijunav Vastivch
2,9011720
2,9011720
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56
add a comment |
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404293%2fclass-with-dataannotation-tabletablename-inherit-by-another-class-with-var%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is your dbcontext, DbSet/IDebSet signature or modelbuilder code and what is the table structure in the db of this table?, my suspicions are that database doesn't have the inherited table at all.. Please update your question with this relevant information
– TheGeneral
Nov 21 at 2:07
Thanks @TheGeneral updated the question above.
– Vijunav Vastivch
Nov 21 at 2:33
Take a look at EF inheritance strategies. What you have currently is Table Per Hierarchy (TPH) which uses single table to store the data for all derived entities.
– Ivan Stoev
Nov 21 at 7:56