Skip to content

Instantly share code, notes, and snippets.

@doggy8088
Created October 20, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doggy8088/3893be4d5897017ad9b5 to your computer and use it in GitHub Desktop.
Save doggy8088/3893be4d5897017ad9b5 to your computer and use it in GitHub Desktop.
使用動態型別取得特定實體的內容
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (var db = new ContosoUniversityEntities())
{
string entityName = "Course";
dynamic data = typeof(ContosoUniversityEntities).GetProperty(entityName).GetValue(db);
foreach (var item in data)
{
Console.WriteLine(item.Title);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment