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

Support for EF Fluent API #90

Open
leevva opened this issue Dec 14, 2016 · 5 comments
Open

Support for EF Fluent API #90

leevva opened this issue Dec 14, 2016 · 5 comments

Comments

@leevva
Copy link

leevva commented Dec 14, 2016

Seems it can't be used fluent API configuration for mapping fields.
Such as http://www.entityframeworktutorial.net/code-first/fluent-api-in-code-first.aspx

@abe545
Copy link
Owner

abe545 commented Dec 14, 2016

No, I didn't create a fluent api for mapping columns to C# properties. I agree that it is something that would be nice to have. Based on your title, it sounds like you'd want to be able to pass a DbModelBuilder to the fluent api to map your POCO. Or would you be okay with a similar api in this library? I'm not sure how open the EF classes are to getting the entity descriptions out, so it would take a bit of work to determine (and I would definitely add it to a separate library, as I don't really want to tie this to EF in general - I know it is for .NET 4.0 code, but I didn't want to re-invent those mapping attributes).

@leevva
Copy link
Author

leevva commented Dec 15, 2016

For mapping properties of my classes i don't use ColumnAttribute but i use HasColumnName method of EntityFramework fluent api.
When stored procedure returns result CodeOnlyStoredProcedures throws exception:

Result Message:
CodeOnlyStoredProcedure.StoredProcedureResultsException : No columns with name all_properties_of_my_class were found in the result set for type my_type.
This property will be ignored if it is decorated with a NotMappedAttribute.
You can also map the property to a different column in the result set with the ColumnAttribute.
If the stored procedure can sometimes return the column, decorate the column with the OptionalAttribute.

Result StackTrace:
at CodeOnlyStoredProcedure.RowFactory.ComplexTypeRowFactory1.CreateRowFactory(IDataReader reader, IEnumerable1 xFormers)
at CodeOnlyStoredProcedure.RowFactory1.ParseRows(IDataReader reader, IEnumerable1 dataTransformers, CancellationToken token)
at CodeOnlyStoredProcedure.StoredProcedure3.Execute(IDbConnection connection, CancellationToken token, Int32 timeout) at CodeOnlyStoredProcedure.StoredProcedure3.Execute(IDbConnection connection, Int32 timeout)

EntityFramework stores mapping in DbContext. It can be retreived this way https://romiller.com/2015/08/05/ef6-1-get-mapping-between-properties-and-columns/

I can't use ColumnAttribute because classes are in domain and they're isolated from data layer.
It's not convinient to create extra classes for result sets.

@leevva
Copy link
Author

leevva commented Dec 15, 2016

@abe545
Copy link
Owner

abe545 commented Dec 15, 2016

Yes, I hear what you're saying. Like I said, it would be a good feature to add as a separate library that is dependent on both EF and CodeOnlyStoredProcedures. In fact, even if the EF folks did some work to support column mappings in a SQL query, CodeOnlyStoredProcedures wouldn't pick it up. My library constructs all the queries itself, so there would need to be an extra mapping layer that looks at the EF fluent mappings.

It is doable, but it will take some time. It is going to require some work that I've been wanting to do to improve the architecture of the mapping between the results and the returned objects. This work will likely take some time, so I can't really give you an estimate on when I'll have something ready, unfortunately.

@leevva
Copy link
Author

leevva commented Dec 16, 2016

Ok, i see. Thanks

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