Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Sql语句查询实体时ColumnAttribute未生效 #144

Closed
pardont opened this issue Dec 2, 2019 · 2 comments
Closed

使用Sql语句查询实体时ColumnAttribute未生效 #144

pardont opened this issue Dec 2, 2019 · 2 comments

Comments

@pardont
Copy link

pardont commented Dec 2, 2019

在使用
fsql.Ado.Query("select * from TestTable ", CommandType.Text).ToList();
查询时,如果列有ColumnAttribute的话,查询出来的列的值为null

使用
fsql.Select().ToList();
查询时,如果列有ColumnAttribute的话,查询出来的列的值正常

表结构和数据:

CREATE TABLE [dbo].[TestTable](
[Id] [int] NOT NULL,
[Name] nvarchar NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
INSERT [dbo].[TestTable] ([Id], [Name]) VALUES (1, N'name1 ')
INSERT [dbo].[TestTable] ([Id], [Name]) VALUES (2, N'name2')

模型代码:

[Table(Name = "TestTable")]
public class TestTable1
{
public int Id { get; set; }
[Column(Name ="Name")]
public string NameColumn { get; set; }
}

@2881099
Copy link
Collaborator

2881099 commented Dec 2, 2019

Ado.Query 是单纯的 ado 操作,对特性设置无效,他是单纯的从实体类找相同名的属性。

ISelect 有特性映射行为,所以正常。

额外提醒,fsql.Select<T>().AsTable 这个方法可以以做 sql 查询。

巧用AsTable

var sql = fsql.Select<User>()
    .AsTable((a, b) => "(select * from user where clicks > 10)")
    .Page(1, 10).ToList()

请注意 AsTable 里面的 SQL 两侧的括号

@pardont
Copy link
Author

pardont commented Dec 2, 2019

回复真神速,厉害。

我觉得既然是指定sql语句查询为类型T的方法,合理是不是应该做一下列属性的处理。

@2881099 2881099 closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants