I am trying to make a generic function to do a database call (see code below). I have put the function in a separate solution, so that i can use it in different projects.
the line:
var data = d.Database.SqlQuery<T> (sql).First();
gives me the error:
Invalid object name 'VM_MailData'
(VM_MailData is the type I add as generic type T)
public static void ProcessData<T>(string Group, int Id)
{
string ConnectionString = "SomeConnectionStringName";
string sql = "select top 1 * from " + (typeof (T).Name) + " where " + Group + "Id = " + Id + ";";
DbContext d = new DbContext(ConnectionString);
var data = d.Database.SqlQuery<T> (sql).First();
//Do some stuff with the data...
html = "some tekst...";
foreach (var sourceProperty in data.GetType().GetProperties())
{
html = html.Replace("{#" + sourceProperty.Name + "#}", sourceProperty.GetValue(data, new object[] { }) == null ? "" : sourceProperty.GetValue(data, new object[] { }).ToString());
//enter code here
}
}
VM_MailDatadoes not matchVW maildata, for oneGroupcome from, and do you know about SQL Injection?