Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not exactly sure what is the problem you are facing: but there is nothing wrong with your T4 code. The signature of the Save method in the second class has new and that's an error:</p> <pre><code>public bool Save(new MyCustomer) </code></pre> <p>should be</p> <pre><code>public bool Save(MyCustomer customer) </code></pre> <p>Also, GetById should return one element not a list.</p> <p>I tried out the code you wrote without connecting to a database by writing dummy classes for Table, Column, etc and there is nothing wrong with the T4 code you wrote, except that, as per your requirements, the code your wrote doesn't generate partial classes, not does it create properties. It just creates a single non-partial class for each table with public fields (not properties). If you want to generate partial classes and properties (and methods) you're in the right direction (I added tabs and newlines to make it look pretty in the generated file, you can just press Ctrl+K, Ctrl+D there to reformat it though:</p> <pre><code>&lt;# foreach (Table tablo in tables) { //start class WriteLine("public partial class My" +tablo.Name+"\n{"); foreach (Column column in tablo.Columns) { if(column.DataType.Name=="nvarchar") WriteLine("\tpublic string " + column.Name+"{get; set;}"); else WriteLine("\tpublic int " + column.Name+"{get; set;}"); } //output the contructor WriteLine("\tpublic My" + tablo.Name + "()\n\t{\n\t\t//constructor\n\t}" ); WriteLine("\tpublic List&lt;" + tablo.Name + "&gt; GetById(int id)\n\t{\n\t\t// do something\n\t}"); //end class WriteLine("}"); //output comment and start class WriteLine("//Delete,Update,Save"); WriteLine("public partial class My" +tablo.Name+"\n{"); WriteLine("\tpublic bool Save(My" + tablo.Name + " " + tablo.Name + ")\n\t{\n\t\t// do something\n\t}"); WriteLine("\tpublic bool Delete(int id)\n\t{\n\t\t// do something\n\t}"); WriteLine("\tpublic bool Update(int id)\n\t{\n\t\t// do something\n\t}"); WriteLine("}"); } #&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload