I've installed the default t4 templates for EF Core into my project, and now I want to edit the EntityType.t4 template so that for any varchar field, I generate a static variable with the max length. For example, the scaffold right now will generate a line like:
public string? CollateralName { get; set; }
When it does that, I also want it to add:
public const int CollateralNamePropertyMaxLength = 50;
I can see in the t4 file where it's writing the property, but I'm not sure how to get the max length of the string from the database column.
Related
Let's assume I have the following C# object:
public class BusinessDetails
{
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
}
Long story short my solution [A] sends a serialised (JSON) List<BusinessDetails> to another external solution [B] that in turn feeds the RDL in question with this and other provided parameters (strings); therefore, on the RDL level I am limited to strings and strings only.
This is all good for simple, one value string parameters but I am interested in dynamically populating table from (JSON 'flattened'/string) List<BusinessDetails> in the mentioned RDL.
I see the available parameter types are:
Text
Boolean
Date/Time
Integer
Float
I guess my question is - can I use the Text/string param to dynamically populate a table in RDL?
Thanks.
short anser NO!
long answer: you dont need that, using the report viewer control you can use the list directly as datasource, when using rdlc instead of rdl you can even consume the class in the reportdesigner, you dont have to come up with ways to align your data source mapping with the data you are recieving
read this for further info: Creating a PDF from a RDLC Report in the Background
the app was bulding fine, until I added some new layouts and when I run it this error shows within the line of codes
enter code
here public static final class id {
public static final int Nexus 5 (5_0")=0x7f070001;
public static final int dummy_button=0x7f070003;
public static final int fullscreen_content=0x7f070000;
public static final int fullscreen_content_controls=0x7f070002;
public static final int switch2=0x7f070004;
in second line: public static final int Nexus 5 (5_0")=0x7f070001;
it underlines it red from Nexus 5 (5_0")=0x7f070001; till the end of that line. what did I do wrong?
Your problem is that Nexus 5 (5_0") is not a valid identifier for a Java variables. You cannot have spaces, for example, in the names. When you declared the new layouts with the new ids, Android Studio automatically took the ID names and created the Java equivalents. The rest of your variables have a valid name and follow the naming convention for resource ids.
Try renaming the ID (in the layout file) to something similar to nexus_5.
The data being returned from a stored procedure has 3 columns of repeating data:
Name | Address | PhoneNumber | UniqueCol1 | UniqueCol2
Ideally I want my model to show that there is repeated data by only storing the values once and have a collection of the unique data.
public class MyViewModel
{
public string Name {get;set;}
public string Address {get;set;}
public string PhoneNumber {get;set;}
public List<MyModel> UniqueData {get;set;}
public class MyModel
{
public string UniqueCol1 {get;set;}
public string UniqueCol2 {get;set;}
}
}
This means I want to map a collection of results to a single object of MyViewModel:
return Mapper.Map<List<StoredProcedureObject>, MyViewModel>(result);
This is where I get my error as I assume I have some configuration that I need to do:
Mapping types:
List`1 -> MyViewModel
Any ideas on the missing step to get this to work?
Automapper is only able to flatten your structure into something simpler. But it's not possible to map a simple class to something more specific.
I would suggest to take only the first entry in your table to fill your base fields like Name, Address, PhoneNumber and iterate over your results to fill your UniqueData List.
I don't see an easier way, because with each possible mapping and without using seperate loops you will get your base data multiple times.
If you don't mind to use another tool, maybe you will have a look at ValueInjecter. I heard you can use this tool for two-way-mappings.
My site is using Subsonic 2.2 on my site.
I have 1 weird situation where I need to run some ad-hoc SQL statements.
public IList<string> GetDistincList(string TableName, string FieldName)
{
string sqlToRun = string.Format("SELECT DISTINCT {0} FROM {1} ORDER BY {0}", FieldName, TableName);
Query query = new Query(TableName);
query.PleaseRunThis(sqlToRun);
query.ExecuteReader();
}
Can anyone help me here? As it appears, I just want to return a generic list of strings.
Thanks!
Subsonic has a great method called ExecuteTypedList() so you can do somethink like this.
List<int> result = DB.Select(Table.Columns.Id)
.Distinct()
.From<Table>()
.OrderBy(Table.Columns.Id)
.ExecuteTypedList<int>();
or even with pocos:
public class UserResult
{
public int Id {get;set;}
public string Name {get;set;}
}
List<UserResult> users = DB.Select(
User.Columns.UserId + " as Id", // the as ... is only needed if your
User.Columns.UserName + " as Name" // column name differs from the
).From<User>() // property name of your class
.ExecuteTypedList<UserResult>();
Unfortunately this method doesn't work for string since it requires
a) a valuetype
b) a class with a parameterless constructor since the method uses reflection to map the columns from the result to the properties of the class
However I wrote an extension method a while ago that works for string:
Use the Subsonic.Select() ExecuteTypedList Method with String
Look at my own answer in the link.
If you add the extensionmethod to your code you can do:
List<String> result = DB.Select(User.Columns.UserName)
.From<User>()
.ExecuteTypedList();
Use the CodingHorror class.
Here's the SubSonic 3 way of doing it: http://www.subsonicproject.com/docs/CodingHorror
The SubSonic 2 way is similar:
Dim ch As SubSonic.CodingHorror
ch.Execute("delete from #tablename", table)
I want to use the Simple Query tool in SubSonic 3(.0.0.2) and the docs page (http://subsonicproject.com/docs/Simple_Query_Tool) implies there's a way to easily get hold of table column names (e.g. Product.ProductNameColumn):
int records = new Select(Product.ProductIDColumn, Product.ProductNameColumn).
From<Product>().GetRecordCount();
The ActiveRecord generated class doesn't appear to expose this info - there is no ProductIDColumn property. Is this a hang-up from version 2?
There's no way to get the column names in SubSonic 3 at the moment. You can still use the simple query tool with strings or if you modify the Structs.tt template you can get them generated for you.
Find this section of code (I think it's line 45):
<# foreach(var col in tbl.Columns){ #>
public IColumn <#=col.CleanName#>{
get{
return this.GetColumn("<#=col.Name#>");
}
}
<# }#>
and modify it so it looks like this:
<# foreach(var col in tbl.Columns){ #>
public IColumn <#=col.CleanName#>{
get{
return this.GetColumn("<#=col.Name#>");
}
}
public static string <#= col.CleanName #>Column{
get{
return "<#= col.Name #>";
}
}
<# }#>
Then you should get all your column names automatically generated as static properties.