Created
October 20, 2015 14:14
-
-
Save doggy8088/3893be4d5897017ad9b5 to your computer and use it in GitHub Desktop.
使用動態型別取得特定實體的內容
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.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