Class with DataAnnotation [Table(“Tablename”)] inherit by another class with variable get set not...












0















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

    – Michael Randall
    Nov 21 '18 at 2:07













  • Thanks @TheGeneral updated the question above.

    – Vijunav Vastivch
    Nov 21 '18 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 '18 at 7:56
















0















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

    – Michael Randall
    Nov 21 '18 at 2:07













  • Thanks @TheGeneral updated the question above.

    – Vijunav Vastivch
    Nov 21 '18 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 '18 at 7:56














0












0








0








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 '18 at 2:20







Vijunav Vastivch

















asked Nov 21 '18 at 1:57









Vijunav VastivchVijunav Vastivch

3,2401722




3,2401722













  • 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

    – Michael Randall
    Nov 21 '18 at 2:07













  • Thanks @TheGeneral updated the question above.

    – Vijunav Vastivch
    Nov 21 '18 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 '18 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

    – Michael Randall
    Nov 21 '18 at 2:07













  • Thanks @TheGeneral updated the question above.

    – Vijunav Vastivch
    Nov 21 '18 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 '18 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

– Michael Randall
Nov 21 '18 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

– Michael Randall
Nov 21 '18 at 2:07















Thanks @TheGeneral updated the question above.

– Vijunav Vastivch
Nov 21 '18 at 2:33





Thanks @TheGeneral updated the question above.

– Vijunav Vastivch
Nov 21 '18 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 '18 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 '18 at 7:56












0






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',
autoActivateHeartbeat: false,
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

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




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

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents