我正在尝试Dapper.我喜欢到目前为止所看到的.为了做简单的CRUD,我使用Dapper.rainbow.它工作得很好.但是,仅当表具有名称为Id的标识列时,它才有效.有这样的db是有意义的,但我不能要求在数据库中更改列名只是为了使用Dapper.为了更清楚,我正在使用像Northwind Db这样的数据库.它在Id列中重复了表名.
为了处理这个问题,我更改了Dapper.Rainbow代码如下:
public T Get(TId id,string idColumnName="Id")
{
return database.Query<T>("select * from " + TableName + " where "+idColumnName+" = @id", new { id }).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来处理这个如列映射/注释或完全不同的东西?
我读过这样的问题
Dapper.Rainbow VS Dapper.Contrib
(我遇到了与Dapper.Contrib类似的小问题,我会另外问一下).
更新 - 不确定答案是否适用于我的Dapper.Rainbow问题(至少,我不知道如何).
提前感谢您的帮助!
我有一个使用业务逻辑层中的接口公开的方法.它如下:
public interface IMyWorkingClass
{
IEnumerable<dynamic> GetSomeList();
}
public class MyWorkingClass : IMyWorkingClass
{
public IEnumerable<dynamic> GetSomeList()
{
dynamic foos = new List<dynamic>();
dynamic item = new ExpandoObject();
item.PropOne = (new Foo()).FooPropertyOne;
item.PropTwo = (new Bar()).BarPropertyOne;
foos.Add(item);
return foos;
}
}
public class Foo
{
public int FooId{get;set;}
public string FooPropertyOne{get;set;}
public string FooPropertyTwo{get;set;}
}
public class Bar
{
public int BarId{get;set;}
public string BarPropertyOne{get;set;}
public string BarPropertyTwo{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
关于动态本身有很多不同的意见/偏好.我觉得它们很有用.我的一位朋友说动力学很好,但上面的方式不是.提出的论点是编译器不会捕获动态对象上发生的变化.我认为单元测试能够抓住那些.所以我不同意.你的专家意见是什么?提前致谢 :)
更新
这里有点清楚(希望)代码:
public interface IMyWorkingClass
{
IEnumerable<dynamic> GetListOfClassesForStudentDynamicReturn();
IEnumerable<StudentClassInfo> …Run Code Online (Sandbox Code Playgroud)