Null result expected real values - sql

When I am trying to get values from database the result set is giving me false and the values are null.
public boolean login()
{
try
{
String p="SELECT * FROM DEMONEW WHERE EMAIL=? AND PASSWORD=?";
pstmt = con.prepareStatement(p);
pstmt.setString(1,EMAIL);
pstmt.setString(2,PASSWORD);
System.out.println("email :"+EMAIL + "and" +"password:"+PASSWORD);
ResultSet res = pstmt.executeQuery();
System.out.println("res :"+ res.next());
while(res.next())
{
NAME = res.getString(1);
System.out.println("NAME FROM MODEL :" +NAME);
AGE=res.getString(2);
System.out.println("age FROM MODEL :" +AGE);
LOCATION=res.getString(3);
System.out.println("email FROM MODEL :" +EMAIL);
EMAIL=res.getString(4);
System.out.println("location FROM MODEL :" +LOCATION);
return true;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
I am expecting the values in database but getting null.

Related

Whats wrong with this SQL Command? It should work

Whats wrong with this sql code? Syntax should be ok or not?
public void setArtikelIdRegalfach(ArrayList <Integer> arikel_ID, int Regal_ID) { // Setzt die Regalfach ArtikelID
try {
String query = "UPDATE WARENLISTE SET ARTIKEL_ID Values (" + arikel_ID + ") WHERE Regal_ID = " + Regal_ID;
st.executeUpdate(query);
}
catch(Exception e) {
System.out.println(e);
}
}
Update statements in SQL do not take a VALUES clause. On top of this, you should be using a prepared statement. Here is a corrected version:
String sql = "UPDATE WARENLISTE SET ARTIKEL_ID = ? WHERE Regal_ID = ?";
try (Connection conn = DriverManager.getConnection("...");
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, arikel_ID);
ps.setInt(2, Regal_ID);
ps.executeUpdate();
}
catch (SQLException e) {
System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
}
catch (Exception e) {
e.printStackTrace();
}

using clearParameter() even thought PreparedStatement is being closed

private PreparedStatement InsertPS = null;
public boolean InsertInDB(String username, String password, double balance, String secret) {
boolean ans = false;
try {
InsertPS = con.prepareStatement("Insert into BankDB values(?,?,?,?)");
String data[] = AMC.SendtoDB(password, secret);
InsertPS.setString(1, data[0]);
InsertPS.setString(2, username);
InsertPS.setString(3, data[1]);
InsertPS.setDouble(4, balance);
int rows = InsertPS.executeUpdate();
if (rows != 0) {
ans = true;
}
InsertPS.clearParameters();
} catch (SQLException sqlInite) {
System.out.println("SQL Error in InsertInDB method: " + sqlInite);
} finally {
try {
InsertPS.close();
} catch (SQLException sqle) {
System.out.println("SQL Exception in InsertInDB method finally clause : " + sqle);
}
}
return ans;
}
Above is the InsertInDB() method given,
It has a InsertPS PreparedStatement Object.
Here is it necessary to use clearParameters() method even though i am closing the InsertPS object at the end of the method.
(I have provided a separate method to close the connection object)
also another question: Is it a good idea to create PreparedStatement Object's outside any method within a class,initializing using Constructor and Say for example Once all Object's (each in different method) are used, close all PreparedStatement Objects using a separate method.
public class JavatoDB {
Driver DM = null;
Connection con = null;
PreparedStatement InsertPS = null;
PreparedStatement BalancePS = null;
PreparedStatement DeletePS = null;
PreparedStatement UpdatePS = null;
PreparedStatement SearchDB = null;
ResultSet RS = null;
ResultSetMetaData RSMD = null;
AdminControl AMC = null;
public JavatoDB() {
AMC = new AdminControl();
try {
DM = new com.mysql.jdbc.Driver();
con = DriverManager.getConnection("jdbc:mysql://localhost/javadb", "java", "javaaccess");
InsertPS = con.prepareStatement("Insert into BankDB values(?,?,?,?)");
BalancePS = con.prepareStatement("Select BALANCE from BankDB where ACCNAME=? AND ACCPIN = ?");
DeletePS = con.prepareStatement("Delete from BankDB where ACCNAME = ? AND ACCPIN = ? ");
UpdatePS = con.prepareStatement("Update BankDB set BALANCE = (BALANCE + ?) where ACCNAME = ? AND ACCPIN = ?");
SearchDB = con.prepareStatement("Select ID AND ACCPIN from BankDB where ACCNAME = ? ");
} catch (SQLException JavatoDBContrsuctor) {
System.out.println("SQL Error in JavatoDBConstructor: " + JavatoDBContrsuctor);
}
}
public boolean InsertInDB(String username, String password, double balance, String secret) {
boolean ans = false;
try {
String data[] = AMC.SendtoDB(password, secret);
InsertPS.setString(1, data[0]);
InsertPS.setString(2, username);
InsertPS.setString(3, data[1]);
InsertPS.setDouble(4, balance);
int rows = InsertPS.executeUpdate();
if (rows != 0) {
ans = true;
}
InsertPS.clearParameters();
} catch (SQLException sqlInite) {
System.out.println("SQL Error in InsertInDB method: " + sqlInite);
}
return ans;
}
Suggestion's or Criticism on other aspects of code are also welcome.
For the first question, when you call:
con.prepareStatement()
a new preparedStatement is created, then parameters dont survive, i mean you dont need to clear then.
About the second question, in your implementation i cant see where you close your preparedStatement, and if you only add close, next time method will fail. Then, it is usual to create the preparedStatement and close it in the same method.

How to auto Increment a primarykey in JDBC sql

can you please guys help me, i'm having trouble on making my primary key into auto-increment, My table name is books and the column that i want to be auto-increment is serial_no which is a primary key.
public class donate extends javax.swing.JFrame {
Connection con;
Statement stmt;
ResultSet rs;
PreparedStatement pst;
DefaultTableModel loginModel = new DefaultTableModel();
int curRow = 0;
/**
* Creates new form donate
*/
public donate() {
initComponents();
DoConnect();
showAll();
}
void showAll(){
try{
rs = stmt.executeQuery("SELECT * FROM books");
while(rs.next())
{
String book = rs.getString("book_title");
String categorie = rs.getString("category");
String status = rs.getString("book_status");
String donators = rs.getString("donator");
int serial_nos = rs.getInt("serial_no");
loginModel.addRow(new Object[]{book, categorie, status, donators, serial_nos});
}
}catch(SQLException err){
System.out.println(err);
}
}
void DoConnect( ) {
try{
//CONNECT TO THE DATABASE
String host = "jdbc:derby://localhost:1527/Dafuq7";
String uName ="Dafuq7";
String uPass ="Dafuq7";
con = DriverManager.getConnection(host, uName, uPass);
//EXECUTE SOME SQL AND LOAD THE RECORDS INTO THE RESULTSET
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM books";
rs = stmt.executeQuery(sql);
}
catch(SQLException err){
JOptionPane.showMessageDialog(donate.this, err.getMessage());
}
}
and here is for may button, which when i input all the data will be submitted to my table books
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String bookttl = bookt.getText();
String yourn = yn.getText();
String categ = cat.getSelectedItem().toString();
String bstat = bs.getSelectedItem().toString();
try {
rs.moveToInsertRow();
rs.updateString( "book_title", bookttl );
rs.updateString( "category", yourn );
rs.updateString( "book_status", categ );
rs.updateString( "donator", bstat );
loginModel.addRow(new Object[]{bookttl, yourn, categ, bstat});
rs.insertRow( );
stmt.close();
rs.close();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM books";
rs = stmt.executeQuery(sql);
}
catch (SQLException err) {
System.out.println(err.getMessage() );
}// TODO add your handling code here:
}
BTW i found another way around by doing this, grabbing my table and reconstructing it and put this code in the create table script
SERIAL_NO INTEGER default AUTOINCREMENT: start 1 increment 1 not null primary key
Simply define your serial_no column as int primary key generated always as identity and then Derby will automatically assign the numbers for you. Here is some example code:
public static void main(String[] args) {
try (Connection conn = DriverManager.getConnection(
"jdbc:derby:C:/__tmp/derbytest;create=true")) {
String sql;
sql = "DROP TABLE books";
try (Statement s = conn.createStatement()) {
s.executeUpdate(sql);
} catch (Exception e) {
// assume table did not previously exist
}
sql = "CREATE TABLE books (" +
"serial_no int primary key " +
"generated always as identity, " +
"title varchar(100))";
try (Statement s = conn.createStatement()) {
s.executeUpdate(sql);
}
sql = "INSERT INTO books (title) VALUES (?)";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, "The Book of Foo");
ps.executeUpdate();
ps.setString(1, "The Book of Bar");
ps.executeUpdate();
ps.setString(1, "The Book of Baz");
ps.executeUpdate();
}
sql = "SELECT * FROM books";
try (Statement s = conn.createStatement()) {
try (ResultSet rs = s.executeQuery(sql)) {
while (rs.next()) {
System.out.println(String.format(
"%d: %s",
rs.getInt("serial_no"),
rs.getString("title")));
}
}
}
} catch (SQLException se) {
se.printStackTrace(System.out);
System.exit(0);
}
}
which produces
1: The Book of Foo
2: The Book of Bar
3: The Book of Baz

Using Matchers for Objects

So I am trying to create a "TestClass" that basically holds onto my Matcher, actual results, error message, and test label.
However, I am slowly starting to realize this might not be possible but I feel like it should be.
Perhaps someone here can help.
Here is what I am trying to do:
public void runTest(){
Assert.assertThat(testLabel + " " + errorMessage, actualResult, testToRun);
}
or, since I am doing Selenium Tests, something like this:
public void runTestAsWebElement(String attributeToCheck){
Object tempActualResult;
switch (attributeToCheck.toLowerCase()){
case "isdisplayed()":
case "isdisplayed":
tempActualResult = ((WebElement) actualResult).isDisplayed();
break;
case "isselected":
case "isselected()":
tempActualResult = ((WebElement) actualResult).isSelected();
break;
case "isenabled":
case "isenabled()":
tempActualResult = ((WebElement) actualResult).isEnabled();
break;
case "text":
tempActualResult = ((WebElement) actualResult).getText();
break;
default:
tempActualResult = ((WebElement) actualResult).getAttribute(attributeToCheck);
}
Assert.assertThat(testLabel + " " + errorMessage, tempActualResult, testToRun);
}
However, I am wondering, will the matchers be able to figure out that the Actual Result is a String or Boolean? Or will it always fail since both objects are being compared as Objects, rather than strings (not sure how the underlying code would be executed).
Any advice on how to properly handle this situation would be much appreciated!
Just to give some context - I am currently writing code like this:
Switch(whatToTest){
case "eye portfolio tests":
customCheckErrorMessages.add("The Eye Portfolio header doesn't match expected user's value");
customCheckActualResults.add(eyePortfolioPage.eyePortfolioAccountHeader);
customCheckExpectedResults.add(holder);
customCheckTests.add(containsString(holder));
customTestAttributeToTest.add("text");
break;
//just showing what my step looks like
}
String actualResult = "";
for(int x = 0; x < customCheckErrorMessages.size(); x++){
try{
switch (customTestAttributeToTest.get(x)){
case "text":
actualResult = customCheckActualResults.get(x).getText();
break;
default:
actualResult = customCheckActualResults.get(x).getAttribute(customTestAttributeToTest.get(x));
break;
}
}catch (IndexOutOfBoundsException e){
//Assuming this field wasn't actually entered. Defaulting to getText
actualResult = customCheckActualResults.get(x).getText();
}
System.out.println("Additional Test #" + (x+1));
Assert.assertThat(customCheckErrorMessages.get(x) + " Expected: \"" + customCheckExpectedResults.get(x)
+ "\", Actual: \"" + customCheckActualResults.get(x).getText().trim(),
actualResult.trim(),
customCheckTests.get(x));
}
I would like to write code like this:
switch(whatIWantToTest){
case "transaction tests":
customTests.add(new TestClass("There should be at least one transaction appearing on the page", //error Message
"Looking For Transactions:", //Test Label
myOrdersPage.transactions.size(), //Actual Result
greaterThanOrEqualTo(1))); //Test to run (should contain expected result)
//Just showing what my step looks like
}
for (TestClass test : customTests){
test.runTest();
}
Here is the code I decided to use. If anyone has a better suggestion I would love to hear it :)
private String testType;
public String errorMessage, testAttribute;
public WebElement actualResult;
public List<WebElement> actualResults;
public String providedStringValue = null;
public Boolean providedBooleanValue = null;
public Matcher testToRun;
public int attempts = 1;
//Empty Constructor
public TestCase() {
errorMessage = "";
testType = "";
actualResult = null;
actualResults = null;
testToRun = null;
providedStringValue = null;
providedBooleanValue = null;
}
//Run Test as a String check
public TestCase(String errorMessage, String providedResult, Matcher testToRun){
this.errorMessage = errorMessage;
providedStringValue = providedResult;
testType = "String";
this.testToRun = testToRun;
}
//Run Test as a Boolean check
public TestCase(String errorMessage, Boolean providedResult, Matcher testToRun){
this.errorMessage = errorMessage;
providedBooleanValue = providedResult;
testType = "Boolean";
this.testToRun = testToRun;
}
//Run Test on a WebElement
public TestCase(String errorMessage, String testAttribute, WebElement actualResult, Matcher testToRun) {
this.errorMessage = errorMessage;
testType = "WebElement";
this.testAttribute = testAttribute;
this.actualResult = actualResult;
this.testToRun = testToRun;
}
//Run Test on a List<WebElement>
public TestCase(String errorMessage, String testAttribute, List<WebElement> actualResults, Matcher testToRun) {
this.errorMessage = errorMessage;
testType = "List";
this.testAttribute = testAttribute;
this.actualResults = actualResults;
this.testToRun = testToRun;
}
public void clearTest() {
errorMessage = "";
testType = "";
testAttribute = "";
actualResult = null;
actualResults = null;
testToRun = null;
providedStringValue = null;
providedBooleanValue = null;
}
public void runTest() {
try {
if (testType.equalsIgnoreCase("WebElement")) {
runTestAsWebElement(testAttribute);
} else if (testType.equalsIgnoreCase("List")) {
runTestAsList(testAttribute);
} else if(testType.equalsIgnoreCase("Boolean")){
runTestAsBooleanCheck();
} else if(testType.equalsIgnoreCase("String")){
runTestAsStringCheck();
} else {
Assert.fail("Don't know how to run this test type");
}
} catch (StaleElementReferenceException e) {
if (attempts < 5) {
System.out.println("StaleElementReferenceException - Running test again");
attempts++;
runTest();
return;
} else {
throw e;
}
}
attempts = 1;
}
private void runTestAsStringCheck(){
Assert.assertThat(errorMessage, providedStringValue, testToRun);
}
private void runTestAsBooleanCheck(){
Assert.assertThat(errorMessage, providedBooleanValue, testToRun);
}
//Sometimes the actualResult is a WebElement which means the value to check is wrapped within another value.
private void runTestAsWebElement(String attributeToCheck) {
Object actualResultHolder;
switch (attributeToCheck.toLowerCase()) {
case "exists":
case "present":
try{
actualResult.isDisplayed(); //Forcing WebElement to look for element. If throws exception, element not found
actualResultHolder = true;
} catch (NoSuchElementException e){
actualResultHolder = false;
}
break;
case"display":
case "displayed":
case "isdisplayed()":
case "isdisplayed":
try{
actualResultHolder = actualResult.isDisplayed();
} catch (NoSuchElementException e){
System.out.println("Element not found");
throw e;
//actualResultHolder = false;
}
break;
case "selected":
case "isselected":
case "isselected()":
actualResultHolder = actualResult.isSelected();
break;
case "enabled":
case "isenabled":
case "isenabled()":
actualResultHolder = actualResult.isEnabled();
break;
case "text":
actualResultHolder = actualResult.getText().trim();
break;
default:
if (attributeToCheck.contains("css: ")) {//In case we want to test the css attribute instead of the HTML attribute
attributeToCheck = attributeToCheck.split("css: ")[1];
actualResultHolder = actualResult.getCssValue(attributeToCheck);
} else {
actualResultHolder = actualResult.getAttribute(attributeToCheck);
}
}
Assert.assertThat(errorMessage + "\n Actual Result = \"" + actualResultHolder + "\" ", actualResultHolder, testToRun);
}
private void runTestAsList(String attributeToCheck) {
switch (attributeToCheck.toLowerCase()) {
case "size":
case "size()":
Assert.assertThat(errorMessage, actualResults.size(), testToRun);
break;
default:
//do nothing - Test has to do with the list of elements.
Assert.assertThat(errorMessage, actualResults, testToRun);
}
}
Then, if for whatever reason I need some other type of test I just add it to the class.

How to create a new table in a database with program that uses entity framework?

I have a piece of software out in the field and I need to add a new table to it. I have the table in my entity framework and new clients get the table. How to I update the others?
ADDED: To make it clear my development and new clients have the table. How to update the older clients databases is the question?
Since it is in my model it seems I should just call a create method and everything should happen under the hood.
_context.NewTable.CreateTable();
But think that I will have to write a sql command string to see if table exists and if it doesn't to create the table.
IDVisitorEntities _context = new IDVisitorEntities ();
String cmd = IF NOT EXISTS ( SELECT [name]
FROM sys.tables
WHERE [name] = NewTable )
CREATE TABLE NewTable (
ID int IDENITY,
NAME VARCHAR(40))
_context.NewTable.CommandText (cmd);
I want to only run this one time if the table doesn't exist. So that doesn't solve that problem. I really don't know what to do.
ADDED 5/6/2013
I'm thinking that EF has the Property Collection for each table and that might hold a clue. Might have to use ICustomTypeDescriptor ... Anyone else have any thoughts?
Added 7/15/2013
I started building it, at my new job, here is a sample. I need to create a file(s) with the partial classes and have the abstract and interface applied to them. It has a long way to go but this is a start...
namespace DataModelMAXFM
{
public abstract class ATable
{
private ArrayList _columns = new ArrayList();
private ArrayList colsToAdd = new ArrayList();
public ArrayList Columns
{
get
{
return _columns;
}
}
public bool TableCreate(SqlConnection sqlConn)
{
//assuming table needs to be created (already checked)
//get column list
//use for loop to create query string
// run command
ITable thisItable;
if (Columns.Count <= 0) //generate column list if not already created
{
if (!ColumnList())
return false;
}
if (this is ITable)
{
thisItable = (ITable) this;
}
else
{
throw new Exception("");
}
StringBuilder sb = new StringBuilder("CREATE TABLE " + thisItable.GetTableName() + " (");
bool flgFirst = true; // to allow for proper comma placement
foreach (PropertyInfo prop in Columns)
{
String propType = this.GetDataType(prop);
if (propType == String.Empty)//check to make sure datatype found a match, EF to SQL
{
return false;
}
if (!flgFirst)
{
sb.Append(", ");
}
else
{
flgFirst = false;
}
sb.Append(prop.Name + " " + propType);
}
// add right parentheses
sb.Append(")");
//now run query created above
SqlCommand com;
try
{
com = new SqlCommand(sb.ToString(), sqlConn);
com.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("TableCreate e:" + e.ToString());
return false;
}
return true;
}
public bool TableExists(SqlConnection sqlConn)
{
SqlDataReader sdr = null;
SqlCommand com;
ITable thisItable;
try
{
//create and execute command
if (this is ITable)
thisItable = (ITable)this;
else
{
throw new Exception("");
}
com = new SqlCommand("Select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = " + thisItable.GetTableName(), sqlConn);
sdr = com.ExecuteReader();
if (!sdr.HasRows)//ie table does not exist
{
return false;
}
}
catch (Exception e)
{
Console.WriteLine("TableCreate e:" + e.ToString());
return false;
}
//close datareader
try
{
sdr.Close();
}
catch (Exception e)
{
Console.WriteLine("close sqldatareader TableExists e: " + e.ToString());
}
return true;
}
public bool ColumnList()
{
bool flgListCreated = false;
PropertyInfo[] propList = typeof(TransactionCategory).GetProperties();
foreach (PropertyInfo prop in propList)
{
if (prop.CanRead && prop.CanWrite)
{
MethodInfo mget = prop.GetGetMethod(false);
MethodInfo mset = prop.GetSetMethod(false);
// Get and set methods have to be public
if (mget == null)
{
continue;
}
if (mset == null)
{
continue;
}
Columns.Add(prop);
if (!flgListCreated)
{
flgListCreated = true;
}
}
}
return flgListCreated;
}
public bool ColumnsExist(SqlConnection sqlConn)
{
ITable thisItable;
if (Columns.Count <= 0)
{
if (!ColumnList())
return false;
}
//2013-07-10 create basic connection and data reader
if (this is ITable)
thisItable = (ITable)this;
else
{
throw new Exception("");
}
SqlDataReader sdr = null;
SqlCommand com;
foreach (PropertyInfo prop in Columns)
{
try
{
//create and execute command
com = new SqlCommand("Select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = " + thisItable.GetTableName() + " and COLUMN_NAME = " + prop.Name, sqlConn);
sdr = com.ExecuteReader();
//if no rows returned to datareader == column does not exist, add to ArrayList of columns to add
if (!sdr.HasRows)
colsToAdd.Add(prop);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
}
//close datareader
try
{
sdr.Close();
}
catch (Exception e)
{
Console.WriteLine("close sqldatareader ColumnsExist e: " + e.ToString());
}
if (colsToAdd.Count == 0)
return false;
//returns true only if method worked and found columns to add to DB
return true;
}
public bool ColumnsCreate(SqlConnection sqlConn)
{
ITable thisItable;
StringBuilder sb = new StringBuilder();
if (colsToAdd.Count <= 0)
{
if (!ColumnsExist(sqlConn)) //2013-07-08 - MAXIMUS\58398(BJH) //if no columns, attempt to create list
return false; // if Column list was not created, return false
}
// add a array of the alter table
if (this is ITable)
thisItable = (ITable)this;
else
{
throw new Exception();
}
sb.Append("ALTER TABLE " + thisItable.GetTableName() + " ADD ( ");
bool flgFirst = true; // allows for no leading comma on first entry
String propType;
foreach (PropertyInfo prop in colsToAdd)
{
//make sure SQL datatype can be determined from EF data
propType = this.GetDataType(prop);
if (propType == String.Empty)
throw new Exception("no datatype match found " + prop.Name + " " + prop.PropertyType.ToString());
if (!flgFirst)
{
sb.Append(", ");
}
else
{
flgFirst = false;
}
sb.Append(prop.Name + " " + propType);
}
sb.Append(" )");
SqlCommand com;
try
{
com = new SqlCommand(sb.ToString(), sqlConn);
com.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
return true;
}
public bool ColumnsUpdate(SqlConnection sqlConn)
{
if (ColumnsExist(sqlConn))
return ColumnsCreate(sqlConn);
else
return false;
}
//method to convert from EF to SQL datatypes, see noted issues
public String GetDataType(PropertyInfo pi)
{
String s = "";
String pistr = pi.PropertyType.ToString();
switch (pistr)
{
case "Byte[]":
s = "binary";
break;
case "Boolean":
s = "bit";
break;
case "String Char[]": // also maps to other options such as nchar, ntext, nvarchar, text, varchar
s = "char";
break;
case "DateTime":
s = "datetime";
break;
case "DateTimeOffset":
s = "datetimeoffset";
break;
case "Decimal":
s = "decimal";
break;
case "Double":
s = "float";
break;
case "Int16":
s = "smallint";
break;
case "Int32":
s = "int";
break;
case "Int64":
s = "bigint";
break;
case "Single":
s = "real";
break;
case "TimeSpan":
s = "time";
break;
case "Byte":
s = "tinyint";
break;
case "Guid":
s = "uniqueidentifier";
break;
case "Xml":
s = "xml";
break;
default:
Console.WriteLine("No datatype match found for " + pi.ToString() + " " + pi.PropertyType.ToString());
return String.Empty;
}
return s;
}
}
public interface ITable
{
int ID
{
get;
}
bool TableUpdate(SqlConnection sqlConn);
bool TableStoredProceduresCreate(SqlConnection sqlConn);
bool TableStoredProceduresDrop(SqlConnection sqlConn);
bool TableCreateTriggers(SqlConnection sqlConn);
bool TableCreateViews(SqlConnection sqlConn);
DataTable GetDataTable();
DateTime dtTableImplemented
{
get;
}
String GetTableName();
}
}
How to I update the others?
And how do you upgrade code of others to require that table? Probably by using some patch or upgrade package and this package should create your table as well.
Since it is in my model it seems I should just call a create method and everything should happen under the hood.
No. EF itself has nothing to define database schema (Except creating SQL script for whole database creation). What you are looking for is possible with EF Migrations but that is feature of EF 4.3 and newer when using code first and DbContext API.