I am using Oracle database as my backend. For my workflow, I am building a dynamic query based on what the user has selected. This dynamic query fetches from the 5 different tables. I am fetching and reading all the columns from all 5 tables so then I can use the same logic from elsewhere as well.
Oracle.ManagedDataAccess.dll is used for the database access.
Code:
public class ClassEx
{
public ClassA ClassA { get; set; }
public ClassB ClassB { get; set; }
public ClassC ClassC { get; set; }
public ClassD ClassD { get; set; }
public ClassE ClassE { get; set; }
public List<ClassEx> Select()
{
List<ClassEx> ex = new List<ClassEx>();
string sql = "Select " + (new ClaasA()).GetFullString("a") + ", "
+ (new ClaasB()).GetFullString("b") + ", "
+ (new ClaasC()).GetFullString("c") + ", "
+ (new ClaasD()).GetFullString("d") + ", "
+ (new ClaasE()).GetFullString("e") +
" From Sysadm.TableA a, Sysadm.TableB b, Sysadm.TableC c, Sysadm.TableD d, Sysadm.TableE e" +
" Where a.Col1 = b.Col2" +
" And a.Col5 = c.Col2" +
" And a.Col6 = d.Col2" +
" And a.Col10 = e.Col2";
GenericDataReader dr = new GenericDataReader(sql);
while(dr.Read())
{
ClassEx dummy = new ClassEx();
dummy.ClassA = new ClassA(dr);
dummy.ClassB = new ClassB(dr);
dummy.ClassC = new ClassC(dr);
dummy.ClassD = new ClassD(dr);
dummy.ClassE = new ClassE(dr);
ex.Add(dummy);
}
return ex;
}
}
public ClassA
{
public int Col1 {get;set;}
...
public DateTime? Col30 {get;set;}
public ClassA(GenericDataReader dr)
{
Col1 = dr.GetInt("A_Col1")
Col2 = dr.GetString("A_Col2")
....
Col30 = dr.GetDateTime("A_Col30")
}
public string GetFullString(string alias)
{
if (!String.IsNullOrEmpty(alias))
alias = alias + ".";
return alias + "A_Col1, " +
alias + "A_Col2, " +
...
alias + "A_Col30"
}
}
public ClassB
{
public int Col1 {get;set;}
...
public DateTime? Col30 {get;set;}
public ClassB(GenericDataReader dr)
{
Col1 = dr.GetInt("B_Col1")
Col2 = dr.GetString("B_Col2")
....
Col30 = dr.GetDateTime("B_Col30")
}
public string GetFullString(string alias)
{
if (!String.IsNullOrEmpty(alias))
alias = alias + ".";
return alias + "B_Col1, " +
alias + "B_Col2, " +
...
alias + "B_Col30"
}
}
public ClassC
{
public int Col1 {get;set;}
...
public DateTime? Col25 {get;set;}
public ClassC(GenericDataReader dr)
{
Col1 = dr.GetInt("C_Col1")
Col2 = dr.GetString("C_Col2")
....
Col25 = dr.GetDateTime("C_Col25")
}
public string GetFullString(string alias)
{
if (!String.IsNullOrEmpty(alias))
alias = alias + ".";
return alias + "C_Col1, " +
alias + "C_Col2, " +
...
alias + "C_Col25"
}
}
public ClassD
{
public int Col1 {get;set;}
...
public DateTime? Col10 {get;set;}
public ClassD(GenericDataReader dr)
{
Col1 = dr.GetInt("D_Col1")
Col2 = dr.GetString("D_Col2")
....
Col10 = dr.GetDateTime("D_Col10")
}
public string GetFullString(string alias)
{
if (!String.IsNullOrEmpty(alias))
alias = alias + ".";
return alias + "D_Col1, " +
alias + "D_Col2, " +
...
alias + "D_Col10"
}
}
public ClassE
{
public int Col1 {get;set;}
...
public DateTime? Col35 {get;set;}
public ClassE(GenericDataReader dr)
{
Col1 = dr.GetInt("E_Col1")
Col2 = dr.GetString("E_Col2")
....
Col35 = dr.GetDateTime("E_Col35")
}
public string GetFullString(string alias)
{
if (!String.IsNullOrEmpty(alias))
alias = alias + ".";
return alias + "E_Col1, " +
alias + "E_Col2, " +
...
alias + "E_Col35"
}
}
Everything work well. Query execution does not take even a second to execute. However, while loop takes 40 seconds to read 750 records.
Which is unacceptable. Can you please help me in improving the while loop.
I am not sure how best it can read all the record in fastest way.
Thank you so much friends for your response.
I have found a bug in my data reader itself when commented out one after another to see the issue. I have found that in one case, it always going in the exception and so it slows down my data reader.
After solving the exception, now I do receive my result in 2 seconds.
Solved!
Thank you once again :)
Related
So I have created a class that holds properties for the names of albums, including their genre, name and artist with an array that will hold the track list. When compiled, the properties' default values are replaced however I don't know how to replace the default values for the array - I don't know how to replace the default track listing with new tracks for each album. Thanks.
Here is the CD.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise_2
{
class Cd
{
string name;
string artist;
string genre;
public string[] tracklist;
public string[] newTracklist;
public string getName()
{
return name;
}
public void setName(string newName)
{
name = newName;
}
public string getArtist()
{
return artist;
}
public void setArtist(string newArtist)
{
artist = newArtist;
}
public string getGenre()
{
return genre;
}
public void setGenre(string newGenre)
{
genre = newGenre;
}
public string[] getTracklist()
{
return tracklist;
}
public void setTracklist(string[] newTracklist)
{
string[] tracklist = newTracklist;
}
public Cd()
{
this.name = "CD Name";
this.artist = "CD Artist";
this.genre = "CD Genre";
this.tracklist = new string[3] { "Track1", "Track2", "Track3" };
this.newTracklist = new string[3] { "newTrack1", "newTrack2", "newTrack3" };
}
}
}
And here is the main.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise_2
{
class Exercise2
{
static void Main()
{
Cd CD1 = new Cd();
CD1.setName("Kill 'Em All");
CD1.setArtist("Metallica");
CD1.setGenre("Thrash Metal");
Cd CD2 = new Cd();
CD2.setName("Ride The Lightning");
CD2.setArtist("Metallica");
CD2.setGenre("Thrash Metal");
Cd CD3 = new Cd();
CD3.setName("Master Of Puppets");
CD3.setArtist("Metallica");
CD3.setGenre("Thrash Metal");
Console.WriteLine(CD1.getName() + " - " + CD1.getArtist() + " - " + CD1.getGenre() + " - " + CD1.getTracklist());
Console.WriteLine(CD2.getName() + " - " + CD2.getArtist() + " - " + CD2.getGenre());
Console.WriteLine(CD3.getName() + " - " + CD3.getArtist() + " - " + CD3.getGenre());
}
}
}
The problem is your setTracklist method creates a new array every time:
public void setTracklist(string[] newTracklist)
{
string[] tracklist = newTracklist;
}
Instead, you need to set the instance tracklist member:
public void setTracklist(string[] newTracklist)
{
tracklist = newTracklist;
}
One more piece of advice. Don't create methods to get and set properties, it's just unnecessary work. Change:
string name;
string artist;
string genre;
public string[] tracklist;
public string[] newTracklist;
To:
public string Name {get; set;}
public string Artist {get; set;}
public string Genre {get; set;}
public string[] Tracklist {get; set;}
You also might want to change tracklist to a List<String> so you can easily add tracks:
public List<String> Tracklist {get; set;}
If you do this, you can create a Cd instance a lot easier:
var newCD = new Cd
{
Name = "Kill 'Em All",
Artist = "Metallica",
Genre = "Thrash Metal"
};
newCD.Tracklist.Add("Hit the Lights");
newCD.Tracklist.Add("The Four Horsemen");
newCD.Tracklist.Add("Motorbreath");
// etc etc
Update:
Here's the full code, in case something got mixed up. I've also implemented a getTracklist method which returns all the tracks is a comma delimited form.
using System;
using System.Collections.Generic;
class Cd
{
public string Name { get; set; }
public string Artist { get; set; }
public string Genre { get; set; }
public List<string> Tracklist { get; set; }
public Cd()
{
Name = "CD Name";
Artist = "CD Artist";
Genre = "CD Genre";
Tracklist = new List<string>();
}
public string getTracklist()
{
return String.Join(", ", Tracklist);
}
}
public class Exercise2
{
public static void Main()
{
Cd CD1 = new Cd();
CD1.Name = "Kill 'Em All";
CD1.Artist = "Metallica";
CD1.Genre = "Thrash Metal";
CD1.Tracklist.Add("Hit the Lights");
CD1.Tracklist.Add("The Four Horsemen");
CD1.Tracklist.Add("Motorbreath");
Cd CD2 = new Cd();
CD2.Name = "Ride The Lightning";
CD2.Artist = "Metallica";
CD2.Genre = "Thrash Metal";
Cd CD3 = new Cd();
CD3.Name = "Master Of Puppets";
CD3.Artist = "Metallica";
CD3.Genre = "Thrash Metal";
Console.WriteLine(CD1.Name + " - " + CD1.Artist + " - " + CD1.Genre + " - " + CD1.getTracklist());
Console.WriteLine(CD2.Name + " - " + CD2.Artist + " - " + CD2.Genre);
Console.WriteLine(CD3.Name + " - " + CD3.Artist + " - " + CD3.Genre);
}
}
You would just write
CD1.setTrackList(new string[] {"Hit The Lights", "The Four Horsemen", "Motorbreath"});
And your setTrackList should read:
public void setTracklist(string[] newTracklist)
{
tracklist = newTracklist;
}
The way you originally wrote it, you were creating a new array of tracks each time you were setting it, instead of setting the backing property.
However, there is a better way to do this. C# has what's called Auto Properties. They handle all this for you.
public string Name {get; set;}
public string Artist {get; set;}
//.... etc
I'm writing this question after long fight with Cassandra database. I would like to insert large collection (~1000000) of Movie objects:
public class Movie
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Year { get; set; }
public string Genres { get; set; }
public int Rating { get; set; }
public string OriginalLanguage { get; set; }
public string ProductionCountry { get; set; }
public int VotingsNumber { get; set; }
public Director Director { get; set; }
}
with nested field Director:
public class Director
{
public Guid Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
I'm using DataStax C# Driver and I tied different ways, but still nothing. Currently my code looks like this:
private void CreateSchema()
{
Session.Execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " +
"= {'class':'SimpleStrategy', 'replication_factor':3};");
Session.Execute("CREATE TYPE IF NOT EXISTS test.director (" +
"firstname text," +
"lastname text," +
"age int," +
");");
Session.Execute("CREATE TABLE IF NOT EXISTS test.Movies (" +
"id uuid," +
"title text," +
"description text," +
"year int," +
"genres text," +
"rating int," +
"originallanguage text," +
"productioncountry text," +
"votingsnumber int," +
"director frozen<director>," +
"PRIMARY KEY (id)" +
");");
}
public string TimeOfCollectionInsert(int collectionEntriesNumber)
{
var watch = new Stopwatch();
try
{
IList<Movie> moviesList = Movie.CreateMoviesCollectionForCassandra(collectionEntriesNumber);
var preparedStatements = new List<PreparedStatement>();
var statementBinding = new List<BoundStatement>();
for (int i = 0; i < collectionEntriesNumber; i++)
{
preparedStatements.Add(Session.Prepare("INSERT INTO test.Movies (id, title, description, year, genres, rating, originallanguage, productioncountry, votingsnumber, actors) VALUES (?,?,?,?,?,?,?,?,?,{ 'director': { firstname: 'DirectorName', lastname: 'DirectorLastname', age: 50 }});"));
}
for (int i = 0; i < collectionEntriesNumber; i++)
{
statementBinding.Add(preparedStatements[i].Bind(moviesList[i].Id, moviesList[i].Title, moviesList[i].Description, moviesList[i].Year, moviesList[i].Genres, moviesList[i].Rating, moviesList[i].OriginalLanguage, moviesList[i].ProductionCountry, moviesList[i].VotingsNumber));
}
watch.Start();
for (int i = 0; i < collectionEntriesNumber; i++)
{
Session.Execute(statementBinding[i]);
}
watch.Stop();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return watch.ElapsedMilliseconds.ToString();
}
Both methods runs successfuly, but I would like to create directors dynamically.
I will be grateful for any help.
btw. Is this good way for measure cassandra bulk insert performace?
Thanks,
P
You have to map your Cassandra UDT (user defined type) director to your Director C# class.
For more information, you should read the documentation :
http://docs.datastax.com/en/developer/csharp-driver/2.7/csharp-driver/reference/21features/mappingUdts.html
I have the following code which allows me to display the gridview exactly as I want,
I need to move the 2 form checkboxes to the same cell but that can be done after.
I am trying to update my database based on the editing done in the DGV, I have set Name, DOB/DOD, Place Of Death, Crem/Burial, Date of Funeral and COR to read only, these values do not need to update back.
Is there a way to map the DTO back to the entity framework or a better way again?
Thanks
private void RefreshDataGrid()
{
var query = (from f in context.funerals
where f.IsPencil == 0
join d in context.deceaseddetails on f.DeceasedID equals d.ID
join i in context.funeralservices on f.ID equals i.FuneralID
where i.IsAlternative == 0
join h in context.htvalues on f.HtValuesID equals h.ID
join p in context.placeofdeaths on f.PlaceOfDeathID equals p.ID
join c in context.coroners on f.CoronerID equals c.ID
let val1 = d.DateOfDeath
let val2 = d.DateOfBirth
let val3 = i.Date
orderby i.Date
select new
{
d.LastName,
d.FirstName,
val2,
val1,
f.CremOrInt,
FormsSigned1 = h.FormsSigned1,
FormsSigned2 = h.FormsSigned2,
PlaceOfDeath = p.PlaceOfDeath1.Substring(0, 15),
val3,
HospOrDocInformed = h.HospOrDocInformed ?? "Unspecified",
CHQorCoroner = h.CHQorCoroner ?? "Unspecified",
CertReq = h.CertReq ?? "Unspecified",
RestingAt = h.RestingAt ?? "Unspecified",
CoffinModel = h.CoffinModel ?? "Unspecified",
SizeAct = h.CoffinSize ?? "Unspecified",
CoffinPlateComp = h.CoffinPlateComp,
HtBy = h.HtBy ?? "Unspecified",
COR = c.Abbrieviation ?? "Unspecified",
Information = h.HTInformation ?? "Unspecified",
RedStatus = h.RedStatus,
YellowStatus = h.YellowStatus,
GreenStatus = h.GreenStatus
}).ToList();
var dataobjects = query.Select(d => new DataBindingProjection
{
DeceasedName = (d.FirstName + Environment.NewLine + d.LastName),
DOBDOD = (d.val2.HasValue ? d.val2.Value.ToShortDateString() : string.Empty) + Environment.NewLine +
(d.val1.HasValue ? d.val1.Value.ToShortDateString() : string.Empty),
DeathPlace = d.PlaceOfDeath,
CremInt = d.CremOrInt,
FuneralDate = (d.val3.HasValue ? d.val3.Value.ToShortDateString() : string.Empty),
HospDoc = d.HospOrDocInformed,
CHQCor = d.CHQorCoroner,
forms1 = d.FormsSigned1,
forms2 = d.FormsSigned2,
CertReq = d.CertReq,
RestingAt = d.RestingAt,
CoffinModel = d.CoffinModel,
SizeAct = d.SizeAct,
CoffinPlate = d.CoffinPlateComp,
HtBy = d.HtBy,
COR = d.COR,
Information = d.Information,
red = d.RedStatus,
yellow = d.YellowStatus,
green = d.GreenStatus
}).ToList();
dataGridView1.DataSource = dataobjects;
dataGridView1.Columns[0].HeaderText = "Last Name" + Environment.NewLine + "First Name";
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].HeaderText = "DOB" + Environment.NewLine + "DOD";
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[2].HeaderText = "Place Of" + Environment.NewLine + "Death";
dataGridView1.Columns[2].ReadOnly = true;
dataGridView1.Columns[3].HeaderText = "Crem/Int";
dataGridView1.Columns[3].ReadOnly = true;
dataGridView1.Columns[4].HeaderText = "Funeral" + Environment.NewLine + "Date";
dataGridView1.Columns[4].ReadOnly = true;
dataGridView1.Columns[5].HeaderText = "Hosp or" + Environment.NewLine + "Doc Informed";
dataGridView1.Columns[6].HeaderText = "CHQ or" + Environment.NewLine + "Coroner";
dataGridView1.Columns[7].HeaderText = "Forms 1" + Environment.NewLine + "Signed?";
dataGridView1.Columns[8].HeaderText = "Forms 2" + Environment.NewLine + "Signed?";
dataGridView1.Columns[9].HeaderText = "Cert" + Environment.NewLine + "Req.";
dataGridView1.Columns[10].HeaderText = "Resting" + Environment.NewLine + "#";
dataGridView1.Columns[11].HeaderText = "Coffin" + Environment.NewLine + "Model";
dataGridView1.Columns[12].HeaderText = "Size" + Environment.NewLine + "Act.";
dataGridView1.Columns[13].HeaderText = "Coffin" + Environment.NewLine + "Plate Comp";
dataGridView1.Columns[14].HeaderText = "HT" + Environment.NewLine + "By";
dataGridView1.Columns[15].HeaderText = "COR";
dataGridView1.Columns[15].ReadOnly = true;
dataGridView1.Columns[16].HeaderText = "Information" + Environment.NewLine + "Of Interest";
dataGridView1.Columns[17].HeaderText = "Red" + Environment.NewLine + "Status";
dataGridView1.Columns[18].HeaderText = "Yellow" + Environment.NewLine + "Status";
dataGridView1.Columns[19].HeaderText = "Green" + Environment.NewLine + "Status";
}
private class DataBindingProjection
{
public string DeceasedName { get; set; }
public string DOBDOD {get; set;}
public string DeathPlace { get; set; }
public string CremInt { get; set; }
public string FuneralDate { get; set; }
public string HospDoc { get; set; }
public string CHQCor { get; set; }
public Boolean forms1 { get; set; }
public Boolean forms2 { get; set; }
public string CertReq { get; set; }
public string RestingAt { get; set; }
public string CoffinModel { get; set; }
public string SizeAct { get; set; }
public Boolean CoffinPlate { get; set; }
public string HtBy { get; set; }
public string COR { get; set; }
public string Information { get; set; }
public Boolean red { get; set; }
public Boolean yellow { get; set; }
public Boolean green { get; set; }
}
Comment by Nilesh worked perfectly, thanks!
Use a Data Transfer Object then bind the DTO to the EF!
I have this simple piece of coding in my Homecontroller.cs, but I receive the error message on the last line, saying "The name 'modToSend' does not exist in the current context". How is that possible? Only in the last line is it not known????
public class HomeController : Controller, IDisposable
{
private MvcEShop2.WcfEshop2Service.Eshop2ServiceClient proxy = null;
private String GetDuration(DateTime startdatum, DateTime einddatum)
{
String maand1 = startdatum.Month.ToString("MMMM");
String maand2 = einddatum.Month.ToString("MMMM");
String duration = "";
if (maand1 == maand2)
{
duration = startdatum.Day.ToString()
+ " - " + einddatum.Day.ToString()
+ " " + maand1
+ " " + startdatum.Year.ToString();
}
else
{
duration = startdatum.Day.ToString()
+ startdatum.Month.ToString("MMMM")
+ " - " + einddatum.Day.ToString()
+ " " + einddatum.Month.ToString("MMMM")
+ " " + startdatum.Year.ToString();
}
return duration;
}
public HomeController()
{
proxy = new MvcEShop2.WcfEshop2Service.Eshop2ServiceClient();
}
struct EventStruct
{
public SEvent Event { get; set; }
public String Duration { get; set; }
};
public ActionResult Index()
{
List<SEvent> modFromWcf = proxy.GetAllEventsByPeriod(#System.DateTime.Now.Year, #System.DateTime.Now.Year + 1, "EN").ToList();
List<EventStruct> modTosend = new List<EventStruct>();
foreach (SEvent item in modFromWcf)
{
EventStruct ES;
ES.Event = item;
ES.Duration = GetDuration(item.StartDate ,item.EndDate);
modTosend.Add(ES);
};
return View("Index", modToSend);
}
}
If that's a direct copy & paste from your code, check the case of the 'S' in your parameter to the View being returned.
public class Teams : INotifyPropertyChanged
{
public string CombinedTeams
{
get
{
return Combined;
}
set
{
{
CombinedTeams += value;
NotifiyPropertyChanged("Combined");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifiyPropertyChanged(string p)
{
if (null != p)
{
PropertyChanged(this, new PropertyChangedEventArgs(p));
}
}
private string Combined
{
get
{
return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;
}
set
{
{
Combined += value;
}
}
}
public string HomeTeam { get; set; }
public string AwayTeam { get; set; }
public string HomeScore { get; set; }
public string AwayScore { get; set; }
}
I got a problem, when trying combine my strings together and having one LONG string that contains all the values from when I parse my XML I only get the First set of values,
basically I get
Team1 Score1 : Score2 Team2
as opposed to
Team1 Score1 : Score2 Team2 Team3 Score3 : Score4 Team4 Team5 Score5 : Score6 Team6
I am binding my Control to CombinedTeams
could you guys help me out? I just want to store the previous string and then combine the new string with the old one, I cant see it being hard but this is confusing me and reading up on it makes me more confused...
Thanks,
John
Your code concatenates the new value to an empty string (last = "").
You probably want to concatenate to the previous value.
I'm not sure what you are expecting, last is always initialized to "", so the += is irrelevant.
Seems like the class called Teams is really a game?
And I don't think setting HomeTeam, AwayTeam, HomeScore, AwayScore over and over again (and then saving this internally somehow) is a good way to keep track of multiple games.
Why don't you look at using a collection of games?
Try something like this:
In a GamesLib library:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace GamesLib
{
public class Game
{
public string HomeTeam { get; private set; }
public string AwayTeam { get; private set; }
public string HomeScore { get; private set; }
public string AwayScore { get; private set; }
public string Combined
{
get
{
return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;
}
}
public Game(string HomeTeam, string AwayTeam, string HomeScore, string AwayScore)
{
this.HomeTeam = HomeTeam;
this.HomeScore = HomeScore;
this.AwayTeam = AwayTeam;
this.AwayScore = AwayScore;
}
}
public class Games : List<Game>, INotifyPropertyChanged
{
public string CombinedTeams
{
get
{
var str = "";
foreach (Game g in this)
{
str += g.Combined;
}
return str;
}
}
public new void Add(Game g)
{
base.Add(g);
if ( PropertyChanged != null ) {
PropertyChanged(this, new PropertyChangedEventArgs("CombinedTeams"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
In a console program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GamesLib;
namespace TestHarness
{
class Program
{
static void Main(string[] args)
{
var gs = new GamesLib.Games();
gs.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(gs_PropertyChanged);
var g = new Game("hometeam", "awayteam", "1", "0");
gs.Add(g);
g = new Game("lions", "bears", "1", "0");
gs.Add(g);
Console.WriteLine("Final result:" + gs.CombinedTeams);
}
static void gs_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var gs = sender as Games;
Console.WriteLine("Changed: " + gs.CombinedTeams);
}
}
}
The reason you are getting the incorrect results is because you have one property referring to another property, and the second property always returns a specific value.
This block of code, when called from elsewhere, will return the results of some other variable called "Combined" which you have defined below...
public string CombinedTeams
{
get
{
return Combined;
}
...
}
private string Combined
{
get
{
return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;
}
...
}
Everything else is academic because you're getter(s) essentially always return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam.
I suspect you will want to restructure your code to be something more like this
public class Teams : INotifyPropertyChanged
{
private string Combined; // Backing for CombinedTeams
public string CombinedTeams
{
get
{
return Combined;
}
set
{
// This only concatinates values; Combined will get longer each time.
Combined += value;
// ViewModels should always notify after the vale has changed
NotifyOfPropertyChange("CombinedTeams");
}
}
// Adds a new team, assuming HomeTeam, HomeScore, AwayScore, and AwayTeam have been initialized
public void AddTeam()
{
CombinedTeams = " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;
}
}
Certainly there are better ways to do that, but that should get you a start, I hope.
General rule (broken all the time by the code-ninjas, which is fine) is that a Property shouldn't do any calculations of it's own, it's really there to allow public access to private data in the class.
It might be worthwhile to run through a couple of articles on C# Properties. Here are some suggestions to get you started: http://msdn.microsoft.com/en-us/library/x9fsa0sw(v=vs.80).aspx and http://msdn.microsoft.com/en-us/library/aa288470(v=vs.71).aspx and of course, some Good Search Results