我是 EF Core 的新手。我的網(wǎng)絡(luò)應(yīng)用程序的某些模型將顯示為下拉控件的列表項(xiàng)。我創(chuàng)建一個(gè)接口和模型如下。public interface ISelectListItemable{ int Id { get; set; } string Name { get; set; }}public class Tag : ISelectListItemable{ public int Id { get; set; } [Required] public string Name { get; set; }}因此我可以創(chuàng)建public static class IEnumerableExtension{ public static IEnumerable<SelectListItem> ToSelectListItem<T>(this IEnumerable<ISelectListItemable> items, int selectedValue) { return from item in items select new SelectListItem { Text = item.Name, Value = item.Id.ToString(), Selected = item.Id.Equals(selectedValue) }; }}輕松獲取SelectListItem列表。問(wèn)題據(jù)我所知,我沒(méi)有看到任何關(guān)于模型實(shí)現(xiàn)接口的教程。所以我的問(wèn)題是我上面的代碼有什么缺點(diǎn)嗎?
如果模型實(shí)現(xiàn)接口有什么缺點(diǎn)?
翻翻過(guò)去那場(chǎng)雪
2023-07-22 16:21:52