Comments (3)
Can you please illustrate with a short (but complete) failing test scenario, so
that we can clearly see the issue?
To clarify - at the moment *no* additional conversions are performed silently,
except for strings<===>enums.
Original comment by marc.gravell
on 14 Jul 2011 at 8:06
from dapper-dot-net.
Hi Marc,
I think the initial issue was that I had no public constructor, thus causing it
to throw. Adding one is far from ideal, but I did so just to see if it would
actually cast implicitly (which it still does not). Here's the test.
public class Slug
{
private string value;
public Slug() { }
public Slug(string value) {
this.value = value;
}
public static implicit operator Slug(string value) {
return new Slug((value ?? string.Empty).Trim());
}
public static implicit operator string(Slug name) {
return name.ToString();
}
public override string ToString()
{
return value;
}
}
[TestFixture]
public class DapperImplicitTests
{
[Test]
public void Should_cast_implicitly()
{
var connection = new SqlConnection("data source=(local)\\sqlexpress;trusted_connection=yes");
connection.Open();
var sql = "select 'test-slug' as Slug";
var slug = connection.Query<Slug>(sql).Single();
slug.ShouldEqual("test-slug");
}
}
Original comment by [email protected]
on 14 Jul 2011 at 8:30
from dapper-dot-net.
Hi, you can do it like that:
(choose which apply)
SqlMapper.AddTypeMap(typeof(Slug), DbType.String);
SqlMapper.AddTypeMap(typeof(Slug), DbType.StringFixedLength);
SqlMapper.AddTypeMap(typeof(Slug), DbType.AnsiString);
SqlMapper.AddTypeMap(typeof(Slug), DbType.AnsiStringFixedLength);
You can add this mapping into the initialization code of you application OR add
it into the static constructor of your Slug to keep it together.
Original comment by masta2ooo
on 16 Jun 2014 at 4:21
from dapper-dot-net.
Related Issues (20)
- Multi mapping requires explicit connection.Open call HOT 4
- Mapping falls if we don't return any data from stored procedure
- Null values from database should overwrite values in object
- Connection not open HOT 1
- Como usar Dapper HOT 8
- Value for LONG Column Type is returned as NULL HOT 4
- Improper oledb parameter regex detection HOT 1
- Specified cast is not valid HOT 1
- Passing a DataTable parameter to a Stored procedure HOT 13
- Multi mapping where split on column is in class definition but not result set HOT 1
- Request to add support for ISupportInitialize Interface or similar HOT 9
- SqlProcedure changes Resultset resulting in Error
- Provide support for custom enum parse
- type not found HOT 3
- SqlMapperExtensions.Update includes computed properties, too
- Enable Dapper to work with columns that use "_" to seperate words. HOT 7
- Dapper.Tvp Nuget Assembly is does not have a strong Name HOT 1
- Please note in the list support docs: no parenthesis
- DBNull With parameter
- Null Reference Exception - DynamicParameters.Get<>() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dapper-dot-net.