1

I am trying to write a T4 template to generate our poco models from the database. I have it generating everything perfectly accept the relationships. I have not gotten the ability to gather the foreignkey information but I am not sure how I can decide when to use a generic list or a property.

example:

public partial class Budget : IGeneratedModel
{
    public int Id { get; set; }
    public int UserId { get; set; }
    public string Name { get; set; }
    public SavingGoal SavingGoal { get; set; } <-- How do I know when to?
    public IEnumerable<SavingGoal> SavingGoals { get; set; }  <-- Or when to?
}

public partial class SavingGoal : IGeneratedModel
{
    public int Id { get; set; }
    public int BudgetId { get; set; }
    public string Name { get; set; }
    public decimal Total { get; set; }
    public bool Active { get; set; }
}

This is the model I have made to hold my relationship data. I can add more it is populated by a SQL query out of a few sys tables.

public class ForeignKeyInfo
{
    public string ForeignTable { get; set; }
    public string ForeignColumn { get; set; }
    public string PrimaryTable { get; set; }
    public string PrimaryColumn { get; set; }
    public string ConstraintName { get; set; }
}

android parse json object use jsontokener

I try to parse json use jsontokener This is my jsontokener code :

try {
        JSONObject jObj = (JSONObject) new JSONTokener(strJson).nextValue();
        String query = jObj.getString("query");
        JSONArray location = jObj.getJSONArray("locations");
        TextView tv = (TextView) findViewById(R.id.dummy_text);
        tv.setText(query);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        TextView tv = (TextView) findViewById(R.id.dummy_text);
        tv.setText("Wrong");
    }

this is my first strJson :

        String strJson = "{"
             + "  \"query\": \"Pizza\", "
             + "  \"locations\": [ 94043, 90210 ] "
             + "}";

and it will show

Pizza

and i try to change strJson to be like this :

        String strJson = "{"
             + "    \"component\":  "
                 + "{"
                    + "  \"query\": \"Pizza\", "
                    + "  \"locations\": [ 94043, 90210 ] "
                 + "}"
             + "}";

and it will show

wrong

That mean code enter to catch. please help me how to improve my code, so it can get query in component.

4

0 回答 0