int 型のオブジェクトの ToString メソッドを呼び出すと、string 型のオブジェクトが戻ります。そして string 型には int 型のオブジェクトを返す Length プロパティがあります。
int i = 10;
string s = i.ToString();
int len = s.Length;
ここで int len = i.ToString().Length のように書くと、i の ToString メソッドを呼び出した結果戻る文字列型のオブジェクトの Length プロパティを変数 len に入れることができます。
同様に table.AsEnumerable().Select(... と書くと、table の AsEnumerable メソッド(正確には拡張メソッド)から戻る IEnumerable<T> インターフェースを持つオブジェクトの Select メソッドを呼び出すことができます。
Microsoft のサンプル SQL Server データベース Northwind をリバースエンジニアリングすると、以下のようなコードが自動生成されます。自力でコードを書く必要はありません。
NorthwindContext コンテキストクラス
C#
1using System;2using System.Collections.Generic;3using Microsoft.EntityFrameworkCore;4using Microsoft.EntityFrameworkCore.Metadata;5using MvcCore6App2.Models;67namespace MvcCore6App2.Data
8{9 public partial class NorthwindContext : DbContext
10{11 public NorthwindContext()12{13}1415 public NorthwindContext(DbContextOptions<NorthwindContext> options)16:base(options)17{18}1920 public virtual DbSet<Category> Categories { get; set;}= null!;21 public virtual DbSet<Customer> Customers { get; set;}= null!;22 public virtual DbSet<Employee> Employees { get; set;}= null!;23 public virtual DbSet<Order> Orders { get; set;}= null!;24 public virtual DbSet<OrderDetail> OrderDetails { get; set;}= null!;25 public virtual DbSet<Product> Products { get; set;}= null!;26 public virtual DbSet<Shipper> Shippers { get; set;}= null!;27 public virtual DbSet<Supplier> Suppliers { get; set;}= null!;2829 protected override voidOnConfiguring(DbContextOptionsBuilder optionsBuilder)30{31if(!optionsBuilder.IsConfigured)32{33 optionsBuilder.UseSqlServer("・・・接続文字列・・・");34}35}3637// ・・・中略・・・3839}40}
Category エンティティクラス
以下の画像の Categories テーブルに対応する Category クラス。
C#
1using System;2using System.Collections.Generic;3using System.ComponentModel.DataAnnotations;4using System.ComponentModel.DataAnnotations.Schema;5using Microsoft.EntityFrameworkCore;67namespace MvcCore6App2.Models
8{9[Index("CategoryName", Name ="CategoryName")]10 public partial class Category
11{12 public Category()13{14 Products = new HashSet<Product>();15}1617[Key]18[Column("CategoryID")]19 public int CategoryId { get; set;}20[StringLength(15)]21 public string CategoryName { get; set;}= null!;22[Column(TypeName ="ntext")]23 public string? Description { get; set;}24[Column(TypeName ="image")]25 public byte[]? Picture { get; set;}2627[InverseProperty("Category")]28 public virtual ICollection<Product> Products { get; set;}29}30}