Entity Framework + stored procedure with paging - entity-framework

I am using Entity Framework now and using a stored procedure to populate my entity.
Where there is no problem with populating my entity, but when i trying to bind the result to a gridview control with "Enable Paging" set to true, it gives an error saying
"The data source does not support server-side data paging."
I am using stored procedure because one of the table column is FullTextIndexed, and there is a requirement to be able to search on that field.
Can anyone tell me how the paging would work in this situation?

I don't have a lot of experiences using the DataSource controls. I usually handle my own data retrieval / binding. Having said that I would allow the stored procedure to return only the records that are being requested (ie. 10-12 for page 2).

Related

Entity framework 4.5 and 5 and serial list processing possible without stored procedure?

My C# application uses EF and calls min() on an int column to get the 'next' number in a sequence of numbers from a database table. The database table already has the next X numbers ready to go and my EF code just needs to get the 'next' one and after getting this number, the code then deletes that entry so the next request gets the following one etc. With one instance of the application all is fine, but with multiple users this leads to concurrency issues. Is there a design pattern for getting this next min() value in a serial fashion for all users, without resorting to a stored procedure? I'm using a mix of EF4.5 and EF5.
Thanks, Pete
Firstly, you can add an timestamp type column into your table and on Entity Framework property window set the concurrency mode to Fixed.
Doing that you enable optimistic concurrency check on the table. If there is another data context tries to interrupt your update, it will generate an excepton.
Check this link: http://blogs.msdn.com/b/alexj/archive/2009/05/20/tip-19-how-to-use-optimistic-concurrency-in-the-entity-framework.aspx?Redirected=true
Alternatively, you can use a TransactionScope object on your select/update logic. You can simply wrap around your code logic with a TransactionScope logic and everything within the scope will be enforced by the transaction.
Check this link for more information:
TransactionScope vs Transaction in LINQ to SQL

How to manage Encrypt* and Decrypt* TSQL functions on an entity property?

I'm using CodeFluent Entities to manage my database for a ASPNET MVC3 web application. I would like to find a way to configure a Property of an Entity in my Model which would be 'transparently' managed with EncryptByPassPhrase and DecryptByPassPhrase TSQL functions.
Example TSQL INSERT/UPDATE (property 'Text') :
-> Add a #PassPhrase(?) parameter to send my key string
-> replace '#Text' by 'EncryptByPassPhrase(#PassPhrase,#Text)
Example TSQL LOAD/SEARCH (property 'Text') :
-> Add a #PassPhrase(?) parameter to send my key string
-> replace '#Text' by 'DecryptByPassPhrase(#PassPhrase,#Text)
Basically, I want to save an encrypted data (from a clear text) and retrieve a decrypted data (from the encrypted field value), without writing stored procedure on my own.
I know I can solve my problem it by creating a custom SQL Stored Procedure for both Save() and Load*() methods, but it seems to me that a tool like CodeFluent Entities might provide a way to feed my needs.
Thanks to anyone that can help me on that ;)
Before anything is actually generated, CodeFluent Entities parses the model and transforms it into a complete memory representation which contains Entities, Properties, Methods, Tables, Columns, Procedures, etc. The inference engine that does this transformation is using a pipeline that’s divided into steps. CodeFluent Entities Aspects can be introduced at any step, and are able to modify the model currently in memory, therefore influencing the next steps.
How to write an aspect is too long to be explained on SO.
You’ll find my complete answer at: http://blog.codefluententities.com/2013/09/25/writing-a-custom-codefluent-entities-aspect-to-encrypt-decrypt-columns-values-at-runtime/

Integrating a Stored Procedure in UnitOfWork/Repository pattern

I've got an application with MVC and Entity Framework. The application uses Unit of Work and Repository patterns for CRUD operations. But I've got to add now a couple of stored procedures that already exist in database. One of them just retrieves data from one of the entities (this is achieved at this moment by the repository pattern) but adds an extra column to the final result, created and populated in the stored procedure.
I want to integrate the use of these stored procedures into my architecture. I've tried to add the stored procedures to my model, map it to the class and use it, but as I have to add an extra column to this entity in the model, I get an error that this field is not mapped.
Should I use my repository for this particular entity just for Add/Edit/Delete and create another entity with the extra field that will be used for just the Get action using the stored procedure?
Thanks.
Should I use my repository for this particular entity just for Add/Edit/Delete and create another entity with the extra field that will be used for just the Get action using the stored procedure
Depends on the use case? Sounds like it's used for a different case and if so I would create a new entity for it.

Data Mapper pattern implementation with zend

I am implementing data mapper in my zend framework 1.12 project and its working fine as expected. Now further more to enhance it i wants to optimize it in following way.
While fetching any data what id i wants to fetch any 3 field data out of 10 fields in my model table? - The current issue is if i fetches the only required values then other valus in domain object class remains blank and while saving that data i am saving while model object not a single field value.
Can any one suggest the efficient way of doing this so that i can fetch/update only required values and no need to fetch all field data to update the record.
If property is NULL ignore it when crafting the update? If NULLs are valid values, then I think you would need to track loaded/dirty states per property.
How do you go about white-listing the fields to retrieve when making the call to the mapper? If you can persist that information I think it would make sense to leverage that knowledge when going to craft the update.
I don't typically go down this path. I will lazy load certain fields on a model when it makes sense, but I don't allow loading parts of the object like this, rather I create an alternate object for use in rendering a list when loading the full object is too resource intensive. A generic dummy list object I just use with tabular data. It being populated from SQL or stored procedures result-sets, usually with my generic table mapper.

entity framework 3.5 and stored procedure result mapping

Using EF3.5 with Visual Studio 2010 (cannot upgrade to EF4 at this point - don't ask!).
Wanting to create a stored procedure that aggregates some fields from some related tables and materialize the result of the stored procedure as a custom "entity". This custom entity would be "read only". I set up the custom entity, the stored procedure, and function import. When I build my Entity project, I get the following:
Error 35 Error 3027:
No mapping specified for the following
EntitySet/AssociationSet -
MyCustomEntitySet
It looks like it wants a table mapping defined for my custom entity, however, I would not have one in this case since it aggregates the data over several tables (and filters out some unneccessary data).
Is it possible to map a custom entity to a stored procedure? Is it possible to do so in a way where the "Update Model From Database" functionality will not break the custom entity or stored proc/function import mapping?
TIA!
We used to get around this by creating a view in the db - the view never actually gets used if you map to stored procedures but it does enable auto-creation of the correct mappings in the entity.
Typically for fairly straight forward procs you can copy/paste the sql to generate the view too - saves some time.