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)?










share|improve this question
























  • 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















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)?










share|improve this question
























  • 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













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)?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...