Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Windows Form Programming Buddies

sinubukan ko lang nag practice kaso kapag madami tables at complex joins mejo complicated na mag map e. tzaka kung 10 tables (10 model classes) hindi naman lahat ng column kukunin ko.

Walang kaso ung 10 tables pa yan, basta may relationship ung mga tables at may linq naman para laruin ung data at iselect lng ung mga columns na gusto mo lang.
 
Walang kaso ung 10 tables pa yan, basta may relationship ung mga tables at may linq naman para laruin ung data at iselect lng ung mga columns na gusto mo lang.

anong ibig mong sabihin ng "basta may relationship" yung table bro? pano kayo mag handle ng CTE at mga partition sa EF?
 
anong ibig mong sabihin ng "basta may relationship" yung table bro? pano kayo mag handle ng CTE at mga partition sa EF?

ung normal na relationship, kung pano ka mag-relationship ng tables sa sql. Diba naglalagay ka ng mga foreignkeys? Kung naka-relationship yang mga tables mo, sa EF may tinatawag na navigation properties, wherein pwede mo maaccess ung mga properties dun sa kabilang sa dun sa kabilang class (mejo magulo explanation ko dito, sana nagets mo ung ibig kong sabihin XD)

example:

Code:
public Class Person{
public  int id {get;set;}
public  string name {get;set;}
public  int age {get;set;}
public int HobbyId {get;set;}
[B]public virtual Hobby Hobby {get;set;}[/B]

}

public Class Hobby{
public int id {get;set;}
public string hobbyname {get;set;}
}

kung magrrefer ko jan sa example ko na yan, pwede mo maaaccess ung mga properties ni Hobby kay Person using navigation properties (yung nka bold)

Code:
var person = GetAllPersons().Where(x=>x.Id == 1).SingeOrDefault();
var hobby= person.Hobby.name;

sana na explain ko ng maayos. i-check mo din ung documentation ng EF.
 
Last edited:
ung normal na relationship, kung pano ka mag-relationship ng tables sa sql. Diba naglalagay ka ng mga foreignkeys? Kung naka-relationship yang mga tables mo, sa EF may tinatawag na navigation properties, wherein pwede mo maaccess ung mga properties dun sa kabilang sa dun sa kabilang class (mejo magulo explanation ko dito, sana nagets mo ung ibig kong sabihin XD)

example:

Code:
public Class Person{
public  int id {get;set;}
public  string name {get;set;}
public  int age {get;set;}
public int HobbyId {get;set;}
[B]public virtual Hobby Hobby {get;set;}[/B]

}

public Class Hobby{
public int id {get;set;}
public string hobbyname {get;set;}
}

kung magrrefer ko jan sa example ko na yan, pwede mo maaaccess ung mga properties ni Hobby kay Person using navigation properties (yung nka bold)

Code:
var person = GetAllPersons().Where(x=>x.Id == 1).SingeOrDefault();
var hobby= person.Hobby.name;

sana na explain ko ng maayos. i-check mo din ung documentation ng EF.

Hindi ako lagi naglalagay ng FK sa mga tables ko unless nag mamaintain ako ng legacy code pero kung nagsisimula ako from scratch di na ko gumagamit ng FK. There are downsides though. Ung navigation properties naman, meron na dati un kahit nung wala pang EF tzaka ung model mo for Person dapat wala ng HobbyId yon.

Parang ganito lang naman ung navigation properties, siguro gumagamit ka naman ng ganto, di mo lang alam na navigation properties na pala yon.
Code:
public class Person
{
    public  Address Address {get;set;}
    public  OtheType OtheType {get;set;}
    
    public Person(string firstName, string lastName)
    {
        //code remove for brevity
    }
}






public class Address
{
    //Add some properties
    //Add some methods
}
public class OtheType
{
    //Add some properties
    //Add some methods
}

Kung babasahin mo yung EF docs
http://www.entityframeworktutorial.net/entity-relationships.aspx

di sila naglalagay ng Id sa main table instead sa details table sila naglalagay.
Parang ganto

Code:
[COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]partial[/COLOR] [COLOR=#0000FF]class[/COLOR] [COLOR=#2B91AF]Standard[/COLOR]
{
    [COLOR=#0000FF]public[/COLOR] Standard()
    {
        [COLOR=#0000FF]this[/COLOR].Teachers = [COLOR=#0000FF]new[/COLOR] [COLOR=#2B91AF]HashSet[/COLOR]<[COLOR=#2B91AF]Teacher[/COLOR]>();
    }
    
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]int[/COLOR] StandardId { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]string[/COLOR] StandardName { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]string[/COLOR] Description { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]virtual[/COLOR] [COLOR=#2B91AF]ICollection[/COLOR]<[COLOR=#2B91AF]Teacher[/COLOR]> Teachers { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
}

[COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]partial[/COLOR] [COLOR=#0000FF]class[/COLOR] [COLOR=#2B91AF]Teacher[/COLOR]
{
    [COLOR=#0000FF]public[/COLOR] Teacher()
    {
        [COLOR=#0000FF]this[/COLOR].Courses = [COLOR=#0000FF]new[/COLOR] [COLOR=#2B91AF]HashSet[/COLOR]<[COLOR=#2B91AF]Course[/COLOR]>();
    }
    
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]int[/COLOR] TeacherId { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]string[/COLOR] TeacherName { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]Nullable[/COLOR]<[COLOR=#0000FF]int[/COLOR]> TeacherType { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]Nullable[/COLOR]<[COLOR=#0000FF]int[/COLOR]> StandardId { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
    [COLOR=#0000FF]public[/COLOR] [COLOR=#0000FF]virtual[/COLOR] [COLOR=#2B91AF]Standard[/COLOR] Standard { [COLOR=#0000FF]get[/COLOR]; [COLOR=#0000FF]set[/COLOR]; }
}
 
Last edited:
Hindi ako lagi naglalagay ng FK sa mga tables ko unless nag mamaintain ako ng legacy code pero kung nagsisimula ako from scratch di na ko gumagamit ng FK. There are downsides though. Ung navigation properties naman, meron na dati un kahit nung wala pang EF tzaka ung model mo for Person dapat wala ng HobbyId yon.

Parang ganito lang naman ung navigation properties, siguro gumagamit ka naman ng ganto, di mo lang alam na navigation properties na pala yon.
Code:
public class Person
{
	public  Address Address {get;set;}
	public  OtheType OtheType {get;set;}
	
	public Person(string firstName, string lastName)
	{
		//code remove for brevity
	}
}






public class Address
{
	//Add some properties
	//Add some methods
}
public class OtheType
{
	//Add some properties
	//Add some methods
}


well, depende sa preference ng developer yan. ako kasi naglalagay ng primary at foreign keys eh
 
Hi mga Boss,

Naghahanap din ako kateam ko.baka pwede kayo..may multi-projects ako and naghahanap ako ng makakasama sana. eheh
 
Back
Top Bottom