This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student { | |
name: string; | |
age: number; | |
constructor(name: string, age: number) { | |
this.name = name; | |
this.age = age; | |
} | |
Print() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CodeFirstDemoApp | |
{ | |
public class Student | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public int Age { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.Entity; | |
namespace CodeFirstDemoApp | |
{ | |
public class Context : DbContext | |
{ | |
public Context() : base() | |
{ | |
} | |
public DbSet<Student> Students { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace CodeFirstDemoApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
CreateStudent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StudentAccount | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public int Amount { get; set; } | |
[Required] | |
public virtual Student Student { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public int Age { get; set; } | |
public virtual StudentAccount StudentAccount { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.Entity; | |
namespace CodeFirstDemoApp | |
{ | |
public class Context : DbContext | |
{ | |
public Context() | |
: base("name=democonnectionstring") | |
{ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void CreateStudent() | |
{ | |
Student s = new Student | |
{ | |
Id = 1, | |
Age = 12, | |
Name = "Foo" | |
}; | |
StudentAccount sa = new StudentAccount | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context c = new Context(); | |
var result = from r in c.Students select r; | |
foreach (var r in result) | |
{ | |
Console.WriteLine(r.Name); | |
Console.WriteLine(r.StudentAccounts.Amount); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student | |
{ | |
public Student() | |
{ | |
StudentAddresses = new HashSet<StudentAddress>(); | |
} | |
public int Id { get; set; } | |
public string Name { get; set; } |
OlderNewer