0

Problem with: Dapper Extensions dbConnection.Get(personId)

I have a model called Person:

Person
{
    public int PersonId { get; set; }
    public string Name { get; set; }
}

In the database I have this table:

data.Persons
    Pers_Id
    Pers_Name

When I try this without any kind of custom mapping, I get an error "Invalid object name 'Person'." I believe this is a mapping issue, because when I completely map the model with the prefix 'Pers_', and use 'data.Persons' Get works.

But is there a way to automatically map with a prefix? The database I'm using has many different tables with different prefices.

I also have everything already mapped to Entity framework. Is there a possibility of getting the map settings from Entity DbModelBuilder?


MS Access Project 2007 SP3 slow performance

I have a project built on MS Access project and There is a strange slow performance issue on MS Access 2007 SP3

I track this issue on two machines that are:

  1. Windows 7 - 64 bit
  2. Microsoft Office Access 2007 (12.0.6606.1000) SP3 MSO (12.0.6607.1000)
  3. SQL SERVER 2008 R2
  4. SQL SERVER Driver (oledb.dll) Version 6.01.7601.17514

There is no difference between two PCs that I try to test but there is obvious slow performance when I open the same screen (I watch SQL SERVER Profiler and I noticed that same query takes 4 sec on first environment and takes 1.5 minute on second environment, and also the Reads column on profiler give a big number for the slow query)

The query is:

SELECT MReceiveNumber, [Line Number], [Item Number], ROW_NUMBER() OVER (ORDER BY [Line Number]) - dbo.GetPrevMRQryLinesCount(MReceiveNumber, [Line Number]) AS Serial FROM tblMReceiveItems

Note: This query takes 2.20 minutes in SQL SERVER Management

So, Is there any performance issue with access 2007 SP3 or there are other things that I should do/review?

Thank you for help.

4

1 回答 1

1

Dapper-Extensions 是基于约定的。对于架构,它使用 .dbo,而对于主键,它使用 Id。如果您的表不符合约定,则必须创建自定义映射

public class MyModelMapper : ClassMapper<MyModel>
{
    public MyModelMapper()
    {

        //use different table name
        Table("table_name");

        //use a custom schema
        Schema("not_dbo_schema"); 

        //have a custom primary key
        Map(x => x.ThePrimaryKey).Key(KeyType.Assigned);

        //Use a different name property from database column
        Map(x=> x.Foo).Column("Bar");

        //Ignore this property entirely
        Map(x=> x.SecretDataMan).Ignore();

        //optional, map all other columns
        AutoMap();
    }
}

另一种方法是使用 Dapper 并编写您的内联查询:

connection.Query("select * from foo.table where myId = {myId}", new {myId})

更新:

另一种选择是使用代码生成和 T4 文本模板

这是一个简单的例子

于 2017-02-02T15:30:08.533 回答