escms / dapper-dot-net Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/dapper-dot-net
License: Other
Automatically exported from code.google.com/p/dapper-dot-net
License: Other
I found cases where i wanted to use the multimap feature but not able and/or
wanting to change the select to the same "Id" column name to split on.
I solved this by added an optional Func to the MultiMap Query methods for the
api user which overides the nextSplit index functionality.
I have created i clone with these changes if any one else should found this
useful. It can be found here:
http://code.google.com/r/mattias-multimap-fine-grain-segment-control/source/
It also solves the issue when there are no "split" columns on the "child"
types. Common when you want to map record sets with many fields to groups of
properties (Like Address ie.)
Sample usage (issues seems not to like lt/gt generics but hopefully you get the
flow):
conn.Query«WorkOrder, Vehicle, Customer, Technician, Location, Booking»(
"SearchVehicleCurrentBookingTechicianLocation @Search",
(workOrder, vehicle, customer, technician, location) =»
new Booking
{
WorkOrder = workOrder,
Vehicle = vehicle,
Customer = customer,
Technician = technician,
Location = location
},
new { Search },
getNextSplitFunc:(reader,splitOn)=»new Queue«int»(
new []
{
reader.GetOrdinal("OrderId"),
reader.GetOrdinal("VehicleId"),
reader.GetOrdinal("CustomerId"),
reader.GetOrdinal("TechnicianId"),
reader.GetOrdinal("LocationId"),
reader.FieldCount
}.Skip(1)
).Dequeue
);
Original issue reported on code.google.com by mattias%[email protected]
on 30 Apr 2011 at 11:37
Please provide a similar class as IntDynamicParam for a more generic
Enumerable<T> where T is a complex type.
It would be useful to allow for another parameter which doesn't need to be
mapped onto a tvp. This should make it clearer what needs to be done to build a
custom dynamic parameters for a sproc that takes as input, tvps and non-tvps.
Original issue reported on code.google.com by [email protected]
on 10 Jul 2011 at 4:32
It would be quite nice if we could log the generated Sql (including params) and
perhaps execution times (both query and mapping).
Perhaps just passing in an optional Action<string>?
cn.Query("select * from foo where foo.Name = @name", new { name = "Foobar" }, s
=> Console.WriteLine(s));
Original issue reported on code.google.com by [email protected]
on 29 May 2011 at 11:53
Not a biggie just for the wish list, which would make debugging easier.
What steps will reproduce the problem?
Have mapped type become invalid because changes in database or
select. i.e. int becomes bigint. SQL Server can "upcast" implicity
if someone wasn't thinking when creating a procedure i.e.
What is the expected output? What do you see instead?
Now we just get an invalid cast exception, would be great if at
least could optin to get an more detailed exception (field name,
field type expected type) or perhaps have an option to have an
InvalidCast callback which gets called with the reader/command
before the exceptions is re thrown and the end user handles
detailed logging.
What version of the product are you using? On what operating system?
changeset: 60:bda6f2c8327a
Please provide any additional information below.
Sample of implicit casting
SELECT 1 AS First,
2147483648 AS Second,
ISNULL(@long, 1) AS Third
will result in:
First int
Second numeric
Third bigint
Original issue reported on code.google.com by mattias%[email protected]
on 28 Apr 2011 at 9:33
Not sure whether I should post here or on SO. Really its just a general
question at you guys how you manage your Dapper scripts.
I've taken to exposing my queries as properties on a static class. This makes
it a bit easier when I need to tweak the query as there's no noise from other
code - see http://codepaste.net/tfb8so
Within my service layer I can then just call:
cn.Query<PostModel>(BlogQueries.PublicPostsQuery, new { .... } )
Notice that I'm also doing a bit of string concatenation to reduce repeating
sql such as the fields to retrieve and the criteria needed twice (once for the
count and once for the select).
Do you guys do something similar or have any other tips?
Original issue reported on code.google.com by [email protected]
on 4 Jun 2011 at 1:50
using code very similar to what you posted here: http://snipt.org/xgnph I am
getting the attached exception.
Here are the POCOs:
public class Post
{
public int ID { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public Author Author { get; set; }
}
public class Author
{
public int ID { get; set; }
public string Name { get; set; }
}
and here is the execution code:
using (var cnn = new SqlCeConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyLittleBlog"].ConnectionString))
{
cnn.Open();
var data = cnn.Query<Post, Author>(@"select * from Posts p left join Authors a on a.ID = p.AuthorID order by p.ID", (post, author) => { post.Author = author; });
var firstPost = data.First();
var title = firstPost.Title;
cnn.Close();
}
running the query against the db returns results just fine:
ID Title AuthorID Body Expr1 Name
1 Post number one 1 stuff in the body. 1 Sam Moore
2 post another 1 more body stuff. 1 Sam Moore
Lemme know if you want me to zip this up or git it so you can test if yourself.
When I tried to check the reader in the GetClassDeserializer Method the HasRows
property was returning an exception("SQL Server Compact does not support calls
to HasRows property if the underlying cursor is not scrollable.").
Original issue reported on code.google.com by [email protected]
on 27 Apr 2011 at 12:37
Attachments:
I have a class containing "char Delimiter" field that is represented in the
database by char(1) column. It is used for CSV parsing.
Using a simple select query, I expect to map some rows from database to a list
of such objects.
Instead, I'm receiving an exception:
System.Data.DataException: Error parsing column 18 (Delimiter=, - String) --->
System.InvalidCastException: Specified cast is not valid.
To reproduce:
1. Create class "Test" with field "public char Delimiter"
2. Create table "Test" with column "Delimiter char(1)"
3. Connection.Query<Test>("SELECT * FROM Test");
If it's not a bug, I would appreciate a suggestion, how to handle this using
Dapper. Thanks.
Original issue reported on code.google.com by [email protected]
on 4 Jul 2011 at 2:59
Can you please add bl-toolkit (http://bltoolkit.net) into the benchmark.
Serdar
Original issue reported on code.google.com by [email protected]
on 6 Apr 2011 at 6:00
Hello World
We're in an environment where Multiple Resultsets are important.
Is there a plan to support this?
i.e.
var results = c.QueryMultiple<Order,IEnumerable<OrderRow>>( ... );
var order = results.First;
var rows = results.Second;
.... etc
Original issue reported on code.google.com by icanhasjonas
on 27 Apr 2011 at 7:27
This may be not an issue, and might be out of scope of dapper...
I have a list of one million objects - and need to insert them into database.
If I use pure ADO .NET with command.prepare and then loop, insert is done in
rought 5 minutes. With dapper and command.execute and loop - insert does not
end within 40 minutes... Would like to read some thoughts and guidance.
Original issue reported on code.google.com by [email protected]
on 22 May 2011 at 12:41
Clone dimon-naumov-dapper-dot-net.
Switched NHibernate to use stateless session.
Added test for Session.Get
Please review and pull.
P.S. Sorry if I used 'Issues' in the wrong way. I found no other options to
make a 'pull request'.
Original issue reported on code.google.com by [email protected]
on 22 Jun 2011 at 9:06
I have the following query:
select t.Title, t.Slug, pt.Post_id as PostId
from BlogPostTags pt inner join Tags t on pt.Tag_id = t.TagId
where pt.Post_id in @ids order by t.Title
And passing an IEnumerable<Guid> to dapper:
var tags = session.Connection.Query(query,new { ids = postIds });
According to mvc-mini-profiler it's generating the following query, which
doesn't look right:
select t.Title, t.Slug, pt.Post_id as PostId from
BlogPostTags pt inner join Tags t on pt.Tag_id = t.TagId
where pt.Post_id in (@ids, ids, ids, ids, ids5) order by t.Title
Is this an issue with the profiler or dapper? The query does appear to be
returning the correct results (in this case it returns the tags for 5 posts)
but I'm not sure why it shows "ids, ids, ids," ?
Original issue reported on code.google.com by [email protected]
on 9 Jun 2011 at 5:44
public static SomeType<T>
{
public static readonly Object SomeObj = new Object();
}
ReferenceEquals(SomeType<int>.SomeObj, SomeType<int>.SomeObj) => true
ReferenceEquals(SomeType<int>.SomeObj, SomeType<long>.SomeObj) => false
So move targetType/parameterType/otherTypes outside Identity for even faster
processing:
private static class QueryCacheHolder<TTarget, TParam,TFirst,...TLast>
{
private statict readonly Dictionary<Identity, CacheInfo> = ...
}
Original issue reported on code.google.com by [email protected]
on 24 May 2011 at 2:42
In rev. 2f73f171cfdf Dapper expects database column names to match property
names exactly. When you have a database naming convention that uses lower case
first letters while the objects adhere to the C# naming conventions (i.e.
upper-case first letters), the properties are never set.
Solution:
Either document the case sensitivity or enable case insensitive property
matching.
For the latter option a single change on line 419 is all it takes:
select new { Name = n, Info = properties.FirstOrDefault(p => p.Name.Equals( n,
StringComparison.OrdinalIgnoreCase ) ) }
).ToList();
Original issue reported on code.google.com by [email protected]
on 19 Apr 2011 at 12:39
What steps will reproduce the problem?
1. Have an query that takes longer than standard timeout (30 seconds)
What is the expected output? What do you see instead?
Optional parameter for commandTimeout
What version of the product are you using? On what operating system?
changeset: 53:ce7137b69e36
Please provide any additional information below.
Have created an clone with commandTimeout implemented
http://code.google.com/r/mattias-dapper-dot-net-commandtimeout/source/checkout
Original issue reported on code.google.com by mattias%[email protected]
on 26 Apr 2011 at 1:45
Would be great if stored procedure output values and return values where
supported.
Don't know if the need is great, but I replaced old linq2sql code with dapper
in a project and the need emerged.
I have made a clone which supports this by adding optional commanType parameter
to the query methods and an ParameterDirection attribute which I decorate the
properties which should get values from output or return value.
Sample parameter class and usage attached, just fragment but you should get the
flow.
Clone can be found here
http://code.google.com/r/mattias-dapper-dot-net-commandtype-storedprocedure-outp
ut/source
This can probably be improved with il & refactored, but it solved my needs.
Original issue reported on code.google.com by mattias%[email protected]
on 3 May 2011 at 3:09
Attachments:
Included the patch for NHibernate
Original issue reported on code.google.com by [email protected]
on 5 Apr 2011 at 1:38
Attachments:
Currently I think the only way to map an entity and a one-to-many association
is by mapping multiple result sets;
It would be nice to be able to do this:
var data = cn.Query<PostModel, IEnumerable<Tag>, PostModel>(query,
(p, tags) => {
p.Tags = tags;
return p;
}, new { id = id });
If this "should" work already then please let me know :)
Original issue reported on code.google.com by [email protected]
on 2 Jun 2011 at 7:02
Can you please make the code database independent like
https://github.com/nberardi/dapper-dot-net
Serdar
Original issue reported on code.google.com by [email protected]
on 6 Apr 2011 at 6:02
What steps will reproduce the problem?
1. Create a base class with a property that has a private setter.
2. Create a derived class.
3. Deserialize the derived class, with the base class property included.
What is the expected output? What do you see instead?
The base class property is ignored.
Please provide any additional information below.
I have implemented a fix. Revision 944d3ebb699b of
http://code.google.com/r/paulbartrum-dapper-dot-net
Original issue reported on code.google.com by [email protected]
on 23 Apr 2011 at 2:05
Steps to reproduce bug:
1. create and open a simple connection
2. execute this sql: connection.ExecuteMapperQuery<DateTime?>("select
null").First().Should().Be.EqualTo(null);
A invalid cast exception is throwed!
Original issue reported on code.google.com by [email protected]
on 13 Apr 2011 at 9:48
Is any work planned to optionally auto-multi-map based off the
AssociationAttribute (or similar)? Or is this completely off the table in order
to stay with POCO or for some other reason?
Nature of relation would be relatively easy (for 1-1, 1-n at least) to
determine (check for IEnumerable<T>/T on involved types)
Manually doing this is kind of tedious (foot work, identity tracking, LOC),
especially for multiple joins. Even though it may be reusable in a limited
fashion in the simple cases.
Example for the attribute usage:
[Association("OtherEntityName", "ThisKey", "OtherKey")]
A first step would not even need caching as it pays in terms of productivity.
I'll do it myself eventually if no one else will do it. But not in the coming
months. Just asking :-)
PS:
AssociationAttribute is stashed away in various DLLs and various forms across
framework versions. But why not just copy it into Dapper for .NET < 4 and keep
to the System.ComponentModel.DataAnnotations namespace for .NET 4, which seems
useful in and of itself.
Original issue reported on code.google.com by [email protected]
on 20 Jul 2011 at 10:36
What steps will reproduce the problem?
1. Create a db table with a DATETIMEOFFSET NULL column.
2. Create a POCO with a DateTime?
3. Trying to select will throw InvalidCastException.
I'm using RIA services to serialize over the wire, and they don't support
DateTimeOffset, so I'm forced to use DatTime.
If I could plug in and provide a Cast helper function or something,
Func<TSource,TResult>.
Original issue reported on code.google.com by [email protected]
on 17 May 2011 at 8:49
What steps will reproduce the problem?
1. Create a .Net3.5 project
2. Try to install dapper.
What is the expected output? What do you see instead?
Expected to get the package installed.
Error message: Install failed. Rolling back...
Unable to find framework assemblies that are compatible with the target
framework '.NETFramework,Version=v3.5'.
What version of the product are you using? On what operating system?
Dapper 1.5, Visual Studio 2010 SP1, Windows 7.
Please provide any additional information below.
The installation fails because of references to .Net 4.0 assemblies.
Original issue reported on code.google.com by [email protected]
on 15 Jul 2011 at 8:28
Attachments:
I have following class definition (.NET version 3.5):
public class Document
{
Binary Report { get; set; }
//other fields
}
In the database table (MS SQL Server 2008) Report field has image data type.
I'm trying execute connection.Query<Document> method and I'm having exception
like this: System.InvalidCastException: cannot cast object of type Syste.Byte[]
to type System.Data.Linq.Binary.
So I can't use SqlMapper with Binary type? Or maybe I'm doing something wrong?
Original issue reported on code.google.com by [email protected]
on 17 Jun 2011 at 1:04
Dapper should attempt to convert values when the property type and result type
do not match.
For example these throw exceptions at the moment when expect Dapper would just
convert them so that they work:
Int16 -> Int32
Int16 -> Bool (i.e. converting 1/0 values to true/false)
Original issue reported on code.google.com by [email protected]
on 27 May 2011 at 3:44
I'd like to be able to (dynamically) iterate over the internal IDictionary of a
FastExpando object.
Implementing a TryConvert method could provide this functionality:
public override bool TryConvert(ConvertBinder binder, out object result)
{
if (binder.Type == data.GetType())
{
result = data;
return true;
}
return base.TryConvert(binder, out result);
}
Original issue reported on code.google.com by [email protected]
on 16 May 2011 at 5:05
What steps will reproduce the problem?
1. Running simple select code for dynamic object.
2. Code throws an exception of Arithmetic Overflow
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
Fixed by changing code
hashCode = unchecked(hashCode * 23 + (sql == null ? 0 : sql.GetHashCode()));
hashCode = unchecked(hashCode * 23 + (type == null ? 0 : type.GetHashCode()));
hashCode = unchecked(hashCode * 23 + (connectionString == null ? 0 : connectionString.GetHashCode()));
Original issue reported on code.google.com by [email protected]
on 22 Apr 2011 at 10:09
there is a need for them
Serdar
Original issue reported on code.google.com by [email protected]
on 13 Apr 2011 at 9:18
I added the Soma library (http://soma.codeplex.com/) as an additional
performance test comparison. You can find the additions at my clone in the
default branch.
http://code.google.com/r/panesofglass-dapper-dot-net/source/detail?r=465edb436e4
07c45dd60fcde630343871d0d5327
Original issue reported on code.google.com by [email protected]
on 28 Apr 2011 at 7:30
Hi guys,
This may be on the same lines as issue 24.
I've got a class that supports implicit casting to/from string.
When dapper tries to do the cast, it falls over. I did try create a custom type
converter, but it doesn't look like this is being used.
Is there anyway I can tell dapper how to convert from string to MyType?
Original issue reported on code.google.com by [email protected]
on 14 Jul 2011 at 8:03
How to use SqlTransaction to insert two tables together?
Original issue reported on code.google.com by [email protected]
on 29 Jun 2011 at 10:55
I posted a question on SO on this topic:
http://stackoverflow.com/q/5898988/64096
Basically what I need is to specify to Dapper how to convert from database data
to strong typed data.
Alternatively, it would also suffice to have Dapper set a private field or
property on the data object so that I can implement data conversion within the
data object (as suggested by Marc Gravell).
The second option is probably what I would use with Linq2Sql.
Original issue reported on code.google.com by [email protected]
on 9 May 2011 at 10:06
What steps will reproduce the problem?
1. Create a sproc with an output parameter
2. In the sproc set the parameter to null
3. Use DynamicParameters to add an output parameter
4. Call sproc with dapper
5. Use DynamicParameters.Get<T> to get value
What is the expected output? What do you see instead?
For dbnulls to be treated as nulls and casted to the destination type
accordingly. Getting an invalid cast exception instead @
"Dapper.DynamicParameters.Get[T](String name)" line 1589.
What version of the product are you using? On what operating system?
1.5, Windows 7, Sql Server 2008 R2
Please provide any additional information below.
Locally I've added a DBNull check to "public T Get<T>(string name)" changing it
from:
(T)parameters[Clean(name)].AttachedParam.Value;
to
var value = parameters[Clean(name)].AttachedParam.Value;
return (T)(value == DBNull.Value ? null : value);
which works well enough.
Original issue reported on code.google.com by [email protected]
on 15 Jul 2011 at 5:56
I've attached the patch for running the same tests but using Simple.Data ORM.
The results aren't brilliant (at least i my machine) but according to Mark
Rendle the performance tweaks will happen for the 1.0 release
(https://twitter.com/#!/markrendle/status/55230529175433216)
Original issue reported on code.google.com by [email protected]
on 5 Apr 2011 at 12:13
Attachments:
> What steps will reproduce the problem?
When I use Multi-Mapping, I get an index outside the bounds of the array
exception in SqlMapper.cs line 892. The code is the Add call here:
var names = new List<string>();
for (int i = startBound; i < startBound + length; i++)
{
names.Add(reader.GetName(i)); <-------- Exception
}
This loop is executed twice. The first finishes without error. On the second,
StartBound is 15 and length is 1. However the reader at this point has just
one row - this an index out of bounds exception.
My calling code is:
var insertMessages = mailDB.Connection.Query<MessageTransfer, AddressTransfer,
MessageTransfer>("SELECT [messageId] ,[folderId] ,[subject] ,[date] ,[header]
,[isRead] ,[isReplied] ,[isForwarded] ,CAST([format] as INT) as
format,[charset] ,[contentSize] ,[content], emailAddress, friendlyName FROM
Messages m LEFT JOIN Addresses a ON a.addressId = m.fromAddressId WHERE
messageId IN @MessageIds", (m, a) => { m.FromAddress = a; return m; },
insertMessageIdsParameter);
The classes in question are:
public partial class MessageTransfer : LiveObject
{
public int MessageId { get; set; }
public int FolderId { get; set; }
public string Subject { get { return _subject; } set { _subject = value == null ? "" : value; } } private string _subject = "";
public DateTime Date { get; set; }
public string Header { get { return _header; } set { _header = value == null ? "" : value; } } private string _header = "";
public bool IsRead { get; set; }
public bool IsReplied { get; set; }
public bool IsForwarded { get; set; }
public ContentFormat Format { get; set; }
public string Charset { get { return _charset; } set { _charset = value == null ? "" : value; } } private string _charset = "";
public int ContentSize { get; set; }
public string Content { get { return _content; } set { _content = value == null ? "" : value; } } private string _content = "";
public override int LiveId { get { return MessageId; } }
...
}
and
public partial class AddressTransfer : TransferObject
{
public string EmailAddress { get { return _emailAddress; } set { _emailAddress = value == null ? "" : value; } } private string _emailAddress = "";
public string FriendlyName { get { return _friendlyName; } set { _friendlyName = value == null ? "" : value; } } private string _friendlyName = "";
...
}
The schema is:
CREATE TABLE [dbo].[Messages](
[messageId] [int] IDENTITY(1,1) NOT NULL,
[folderId] [int] NOT NULL,
[subject] [nvarchar](max) NOT NULL,
[fromAddressId] [int] NOT NULL,
[date] [smalldatetime] NOT NULL,
[header] [nvarchar](max) NOT NULL,
[isRead] [bit] NOT NULL,
[isReplied] [bit] NOT NULL,
[isForwarded] [bit] NOT NULL,
[format] [int] NOT NULL,
[charset] [varchar](64) NOT NULL,
[contentSize] [int] NOT NULL,
[content] [nvarchar](max) NOT NULL
)
and
CREATE TABLE [dbo].[Addresses](
[addressId] [int] IDENTITY(1,1) NOT NULL,
[emailAddress] [nvarchar](256) NOT NULL,
[friendlyName] [nvarchar](256) NOT NULL
)
Please let me know if I can provide any other information.
Original issue reported on code.google.com by [email protected]
on 29 May 2011 at 7:07
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
Please use labels and text to provide additional information.
Original issue reported on code.google.com by [email protected]
on 29 Apr 2011 at 11:10
From my question on SO:
http://stackoverflow.com/questions/6711012/dapper-like-operator-using-dynamicpar
ameters
----------------------------------
This works:
var list = conn.Query<int>(
"select Id from Person where Id in @ids",
new { ids = new int[] { 1, 2, 3 } }
);
This throws "No mapping exists from object type System.Int32[] to a known
managed provider native type.":
DynamicParameters parameters = new DynamicParameters(
new { ids = new int[] { 1, 2, 3 } }
);
var list2 = conn.Query<int>(
"select Id from Person where Id in @ids",
parameters
);
Original issue reported on code.google.com by [email protected]
on 15 Jul 2011 at 7:45
What steps will reproduce the problem?
1. Create a table and stored procedure (SpGetAllPersons) which returns below
schema:
PersonGUID, FirstName, LastName, Age, Sex, Address
2. Create model as per below:
Class Person
{
int PersonGUID { get; set; }
Name name { get; set; }
int Age { get; set; }
bool Sex { get; set; }
string Address { get; set; }
}
3. Write a dapper query to populate fields.
List<Person> persons = DbConn.Query<Name,Person,Person>
("SpGetAllPersons",
(name,person) => {person.Name = name; return person;}
commandType: CommandType.StoredProcedure,
splitOn: "PersonGUID, Age, Sex, Address").ToList();
What is the expected output? What do you see instead?
Expected Output : All the values should be prefilled correctly into Model.
Actual Output : All the IDs were 0.
What version of the product are you using? On what operating system?
Windows XP Sp3, .NET 4.0, SQL Mapper version: acacfa6a6d59
Please provide any additional information below.
I debugged the code and found below:
Line 496: There is a function like below:
Func<int> nextSplit = () =>
{
var currentSplit = splits[splitIndex];
if (splits.Length > splitIndex + 1)
{
splitIndex++;
}
int pos;
for (pos = current + 1; pos < reader.FieldCount; pos++)
{
// some people like ID some id ... assuming case insensitive splits for now
if (splitOn == "*" || string.Equals(reader.GetName(pos), currentSplit, StringComparison.InvariantCultureIgnoreCase))
{
break;
}
}
current = pos;
return pos;
};
Here Pos starts from 1 instead of 0 so it will always skip the 1st column of
Reader. I removed 1 and Dapper started populating all the ID values correctly.
Original issue reported on code.google.com by [email protected]
on 7 Jun 2011 at 11:27
What steps will reproduce the problem?
1.return conn.Query<RecordModel,RecordTypeModel,RecordModel>(
"SELECT RCD_ID,RCD_RTP_ID,RCD_DT,CRD_TITLE,RCD_AMOUNT,RCD_PLACE,RCD_MEMO,RCD_TYPE,RTP_ID,RTP_NAME,RTP_FLAG FROM BRECORD A LEFT JOIN RRECORDTYPE B ON A.RCD_RTP_ID = B.RTP_ID ORDER BY A.RCD_ID ",
(record, type)
=>
{
record.TYPE = type;
return record;
},splitOn:"RTP_ID")
.ToList<RecordModel>();
2.public static void ThrowDataException(Exception ex, int index, IDataReader
reader)
{
string name = "(n/a)", value = "(n/a)";
if (reader != null && index >= 0 && index < reader.FieldCount)
{
name = reader.GetName(index);
object val = reader.GetValue(index);
if (val == null || val is DBNull)
{
value = "<null>";
}
else
{
value = Convert.ToString(val) + " - " + Type.GetTypeCode(val.GetType());
}
}
throw new DataException(string.Format("Error parsing column {0} ({1}={2})", index, name, value), ex);-----throw DataException
}
What is the expected output? What do you see instead?
System.InvalidCastException: Error parsing column 10 (RTP_FLAG=True - Boolean)
----------------------------------------
Please help me,Thanks!
Original issue reported on code.google.com by [email protected]
on 16 Jun 2011 at 11:56
This isn't a bug report, it's a feature request/wish..
A lot of databases have strange behaviors when it comes to storing, indexing
and querying boolean fields.
Most databases combine multiple bit fields in storage to save storage space.
The downside of this, is that this costs performance and some database engine
refused to index bit fields.
One of the more popular workarounds is to store booleans fields as TinyInt.
When false is equal to zero and true to everything else (> 0).
And as diskspace is cheap and CPU resources are expensive I also often use this
workaround as a optimalization technique.
How to reproduce the situation.
[SQL]
CREATE TABLE Users (UserID int IDENTITY(1,1) not null, Email varchar(255) not
null, Password Char(40) not null, Active TinyInt not null, )
GO
ALTER TABLE Users ADD CONSTRAINT PK_Users PRIMARY KEY CLUSTERED (UserID)
GO
ALTER TABLE Users ADD CONSTRAINT DF_Users_Active DEFAULT (0) FOR Active
GO
[C#]
public class User
{
public User()
{
Email = Password = String.Empty;
}
public int UserID { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool Active { get; set;
}
SqlConnection conn = new SqlConnection("server=...;");
conn.Open();
//This query will throw an conversion exception (boolean != TinyInt)
var activeUsers = conn.ExecuteMapper<User>("SELECT UserID, Email, Password,
Active FROM Users WHERE (Active=1)");
In the past I have written an DataRecordHelper class that accepts a data reader
as input. My GetBoolean(int ordinal) method uses GetFieldType() to determine
the underlying data type. If it's a bit field it uses GetBoolean, if it's a
tinyint it uses GetByte() or it uses GetIntxx() when it's a SmallInt or a
regular integer.
Well this isn't the fastest way to convert data types, it is simple and easy to
understand. For dapper.net it might be feasable to use an array of expression
to specify a custom conversion.
For now I'm using a workaround like:
(Query has changed to 'SELECT UserID, Email, Password, Active as _Active FROM
Users ...')
public class User
{
...
public bool Active
{
get { return _Active > 0; }
set { return _Active = value ? 1 : 0; }
}
//Alias property for mapping tinyint <--> boolean
public int _Active { get; set; }
}
Original issue reported on code.google.com by [email protected]
on 28 Jun 2011 at 7:51
Not a bug, just a feature request.
It looks like there is currently a limit of about 4 joins in a Multi Map query,
which most of the time is fine, but occasionally we need to join on more tables
than this.
Can this limit be increased to permit up to about 10 joins please?
Original issue reported on code.google.com by [email protected]
on 19 Jul 2011 at 12:18
What steps will reproduce the problem?
1. Just use a Firebird connection and do a Query(sql)
2. It should throw when executing
What is the expected output? What do you see instead?
Expected is the same result as you would get by doing a manual ExecuteReader.
Instead you get an InvalidOperation exception
What version of the product are you using? On what operating system?
I used a clone of r4e36b1b7019f.
Please provide any additional information below.
I used Firebird .Net Data Provider v 2.6.0
(http://www.firebirdsql.org/index.php?op=files&id=netprovider)
Original issue reported on code.google.com by [email protected]
on 25 Apr 2011 at 6:04
This is noway a bug, but rather a question: is pagination on SO is done with
Dapper as well?
Does it explicitly provide any means for that? Or should one resort to
low-level t-sql practices?
Original issue reported on code.google.com by [email protected]
on 6 May 2011 at 12:31
What steps will reproduce the problem?
1. Try and compile latest version.
I'd rather not include extraneous DLL references if I can help it.
Original issue reported on code.google.com by [email protected]
on 30 Apr 2011 at 10:39
What steps will reproduce the problem?
1. Create a query to return multiple result sets, one of which will create an
object with two additional types (see attached test).
2. Run the query, mainly the result set for the three objects
What is the expected output? What do you see instead?
The object with two nested objects should be returned from the Read method.
Instead, an exception is thrown:
Unable to cast object of type
'System.Func`4[SqlMapper.Tests+Post,SqlMapper.Tests+User,SqlMapper.Tests+Comment
,SqlMapper.Tests+Post]' to type
'System.Func`3[SqlMapper.Tests+Post,SqlMapper.Tests+User,SqlMapper.Tests+Post]'.
What version of the product are you using? On what operating system?
v1.4, Windows 7 64bit Ultimate
Please provide any additional information below.
The problem is in the GridReader class, the MultiReadInternal method. When
SqlMapper.MultiMapImpl is called, it is ignoring all but the first two type
parameters, instead using DontMap. Changing this to use the other types makes
it function correctly (see attached file).
Original issue reported on code.google.com by [email protected]
on 15 Jul 2011 at 2:18
Attachments:
I would appreciate support for ExecuteScalar.
This makes it easy to to do inserts and get the generated row id as a result.
I've implemented this based on the ExecuteCommand implementation and it works
for me so far.
Original issue reported on code.google.com by [email protected]
on 9 May 2011 at 10:18
Attachments:
Are there any plans to support enums?
If not, some kind of mapping override as suggested by Matt
(http://code.google.com/p/dapper-dot-net/issues/detail?id=24) would be useful.
This way we could cast to the enums ourselves.
Original issue reported on code.google.com by [email protected]
on 3 Jun 2011 at 3:58
When calling a stored procedure with output parameters I have to create a
DynamicParameters object like this:
DynamicParameters p = new DynamicParameters();
p.Add("@GameID", gameId);
p.Add("@GUIDin", sessionId);
p.Add("@StandIDin", standIDin);
p.Add("@sectionin", section);
p.Add("@zonein", zone);
p.Add("@NumberOfSeats", numberOfSeats);
p.Add("@SeatTypeIDin", seatTypes);
p.Add("@SeatCountOut", dbType: DbType.Int32, direction:
ParameterDirection.Output);
It would be nice if most of the parameters could be initialized using an
anonymous object like other calls using Dapper.Net, and then the
output/ref/return parameters are added as needed:
DynamicParameters p = DynamicParameters.FromObject({ gameid, sessionId,
standIDin, section, zone, numberOfSeats, seatTypes });
p.Add("@SeatCountOut", dbType: DbType.Int32, direction:
ParameterDirection.Output);
Original issue reported on code.google.com by [email protected]
on 31 May 2011 at 10:34
What steps will reproduce the problem?
1. download dapper from nuget or by hand
2. open a connection to an Oracle 10 or 11 db
3. run the sample test code
4. exception
What is the expected output? What do you see instead?
System.ArgumentException was caught
Message=Value does not fall within the expected range.
Source=Oracle.DataAccess
StackTrace:
at Oracle.DataAccess.Client.OracleParameter.set_DbType(DbType value)
at ParamInfo6757459b-c923-49af-aba7-97aefc1b85fe(IDbCommand , Object )
at Dapper.SqlMapper.SetupCommand(IDbConnection cnn, IDbTransaction transaction, String sql, Action`2 paramReader, Object obj, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\code\VisionCore\BE\PPCOM\CoreLogic\Com.BE.BizLib\Com.BuyEfficient.Entity\Dapper\SqlMapper.cs:line 1036
at Dapper.SqlMapper.<QueryInternal>d__4`1.MoveNext() in C:\code\VisionCore\BE\PPCOM\CoreLogic\Com.BE.BizLib\Com.BuyEfficient.Entity\Dapper\SqlMapper.cs:line 395
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\code\VisionCore\BE\PPCOM\CoreLogic\Com.BE.BizLib\Com.BuyEfficient.Entity\Dapper\SqlMapper.cs:line 351
at TestProject.UnitTest1.TestDapper() in C:\code\VisionCore\BE\PPCOM\CoreLogic\Com.BE.BizLib\TestProject\UnitTest1.cs:line 41
InnerException:
What version of the product are you using? On what operating system?
1.4
Windows 7 64bit Enterprise
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 17 Jun 2011 at 4:28
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.