【发布时间】:2017-10-13 06:27:19
【问题描述】:
我是 asp.net 核心 MVC 框架的新手(在此之前我使用的是 Laravel。)
我有两张表,Country 和 State,我将使用 InnerJoin 加入这两张表。
在我的 CountryModel 中,我有 4 个如下属性
public int CountryId { get; set; }
public string CountryName { get; set; }
public int StateId { get; set; }
public string StateList { get; set; }
SELECT c.CountryId,
c.CountryName,
s.StateId,
s.States AS 'StateName'
FROM _tbAddr_Country AS c
INNER JOIN _tbAddr_State AS s on s.CountryId = c.CountryId
以上是我的 sql 查询,在我的 Country Model 属性中我没有“StateName”属性但我有“StateList”,我只想使用 DataAnnotation 将“StateList”映射到“StateName”,如下所示,我有试过了
[ColumnAttribute("StateName")]
public string StateList { get; set; }
和
[Column("StateName")]
public string StateList { get; set; }
这两个对我不起作用,我知道我可以通过简单地将“StateList”更改为“StateName”来解决这个问题,但我希望我能找到替代方法,比如使用“Column”或“ColumnAttribute”数据注释来解决这个问题。任何帮助表示赞赏。
P/S:我使用 .net core 1.1 和 SQL Server Management Studio 2014
【问题讨论】:
-
您是否使用了正确的 nuget 包,请从这里交叉检查packagesearch.azurewebsites.net/?q=ColumnAttribute
-
感谢您的回复!如何确保我使用的是正确的包?因为我是 asp.net core 的新手。
标签: sql-server asp.net-core data-annotations