假設我有2個類(其中一個來自我的實體框架,另一個是全局的,它在整個應用程序中可用,而EF一個不是)它們都具有相同的屬性和田野。除了這個例子,有沒有一種更簡單快捷的方式將實體類轉換爲全局類?將1類轉換爲另一個具有相同字段的類
全球一個:
public class CompanyOwner
{
public Guid OwnerId { get; set; }
public string CompanyName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
}
實體模型類
public class dbOwner
{
public Guid OwnerId { get; set; }
public string CompanyName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
}
的方式即時通訊現在在做什麼吧:
CompanyOwner owner = new CompanyOwner();
Owner dbOwner = entities.FirstOrDefault(.....)// some LINQ
owner.CompanyName = dbOwner.CompanyName;
owner.Address = dbOwner.Address;
owner.Email = dbOwner.Email;
owner.Phone = dbOwner.Phone;
Plusone精選不懶惰像我一樣;-) – gsharp
這是真正有用的.. TNX – vlad