I tried to use CreateQuery method or ExecuteStoreQuery by refrening the below link
Actually I need to Get the data using MYSQL query but i didn't find any method for that i am trying with the sql method in entity those are also not working, like this how to add MySQL query in Entity Framework?
http://www.entityframeworktutorial.net/Querying-with-EDM.aspx
I added both the namespace
using System.Data.Objects;
using System.Data.Entity;
still I didn't get those two methods can any one help me
Since ESQL was considered an advanced use case, there is no straightforward API from DbContext. You can access the ObjectContext that backs your DbContext to do what you want:
((IObjectContextAdapter)context).ObjectContext.CreateQuery<Person>("esql..")
Refer Below Link
Can't find CreateQuery() method
Related
I am using CodeIgniter from 2 years and i am trying to move to Laravel and I saw many tutorials of how to use Laravel but i couldn't find any answers to how to pass variables to functions using the URL and without using routes like in CodeIgniter if i called this link
site.com/users/edit/12.
I would be calling the users controller , the edit function and passing a variable of value 12
how can i do the same in Laravel without using routes for every single function or using query strings which will make the URL ugly?
Here is an example.Hope that it will be helpful.......
route.php
Route::controller('users','UsersController');
UsersController.php
class UsersController extends BaseController
{
public function getEdit($value)
{
echo $value;
}
}
url
site.com/users/edit/12
output
12
In Laravel - 3 you may do it using something like this:
Route::controller(Controller::detect());
But in later versions it's not available and you should explicitly declare the routes. Actually it's better to declare routes explicitly and this approach has many benefits too. This is a common problem that happens to developers who migrates from CodeIgniter but later they get motivated and if you use this you'll love this for sure.
You may read this article by Phil Sturgeon who was the man behind the CodeIgniter framework, he discussed about it's down sides of this (automatic routing).
If you are using Laravel - 4 then check the Controllers Manual, specially check out the RESTful and Resourceful controllers section, it may attract you but be familiar with explicit route declaration first.
I've created a library class file in my CakePHP 2.0 app. It's a single PHP class called emailManager Which exists within a folder emailManager within CakePHP's libaray folder. I would love to know what is the simplest way to reference the database from this library class.
I would love to be able to do something like $this->AppModel->query("SELECT * FROM some_table_in_my_db"), that way I do not have to track DB configurations in separate places, but I'm not sure how to achieve this.
Also, I feel it is important to mention that the tables I am working with do not adhere to CakePHP table naming convention. They predate our use of CakePHP and so I cannot change my tables to fit CakePHP's model format. this is why I want generic database access via something like query
EDIT: I have constructed a temporary solution, but I know a better one is possible.
I have a model in my cake app called MySimpleConstuct and then in the library file I include the MySimpleConstruct Model as followed:
// import this model
$this->GivenModel = ClassRegistry::init('MySimpleConstruct');
$this->GivenModel = new MySimpleConstruct();
// Then it is possible to do as followed:
$table_data = $this->GivenModel->query('SELECT * FROM like_some_table_dude' WHERE 1);
This is not ideal so I still searching for a better solution.
Any help would be greatly appreciated.
#John Galt, I suppose it's not an exact duplicate but it is very similar and the resolution does appear to apply to your situation very directly.
The other technique you could consider using would be to instantiate the Library in the controller and than give it a reference of the model.
class TestController extends AppController {
function index(){
App::uses('TheLibrary', 'Lib');
$obj = new TheLibrary();
$obj->GivenModel = &$this->GivenModel;
}
}
-EDIT-
And then within the library you've written do something like this.
class TheLibrary {
var $GivenModel = null;
function some_query(){
return $this->GivenModel->query('SELECT * FROM like_some_table_dude WHERE 1');
}
}
The first code snippet is of the Controller instantiating your library and then giving the library a reference to the Model as the property GivenModel. The "&" symbol makes the assignment a reference (see How does the '&' symbol in PHP affect the outcome?). The second code snippet is of a sample of how the library would use that property.
I do understand that you are trying to use a model from the library and that is what the solution you have in your edit and my proposed solution both do. However I will note again that this is not proper MVC convention and you should reconsider how you are using Libraries.
I often see Grails sample code where the programmer has called a method called encodeAsHTML(). I figure I should probably use this in my Grails applications (for security reasons, I assume?), but I was wondering when I should use this method. What objects/properties/etc. are candidates for the encodeAsHTML() method?
Thank you!
Use encodeAsHTML() (or encodeAsJavaScript, etc) for everything that you've got from user. For every string that could be modified by user (got from input form, from request parameter, from external API call, etc)
See also:
https://en.wikipedia.org/wiki/Cross-site_scripting
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
I am not sure when this was introduced to Grails, but if in Config.groovy you set grails.views.default.codec="html" then encodeAsHTML() is called whenever you use ${} in GSPs.
Source: http://alwaysthecritic.typepad.com/atc/2010/06/grails-gsp-html-escaping-confusion.html
I am trying to use SimpleMembership with MySql and I cant get it to work.
I downloaded the latest devart connector for MySql and followed the instructions on
http://www.devart.com/dotconnect/mysql/articles/extendedmembership-tutorial.html
The problem is that the WebSecurity class provided by devart, only has the InitializeDatabaseConnection method but it misses the rest of the methods WebMatrix.WebData has. (i.e UserExists(), CreateAccount(), etc )
Does anyone knows any implementation of WebSecurity alternative to WebMatrix.WebData?
We have implemented the InitializeDatabaseConnection method in the Devart.Common.Web.WebSecurity class because there was no way to override the corresponding method of the WebMatrix.WebData.WebSecurity class.
Other methods of the WebMatrix.WebData.WebSecurity class are supported in our implementation and can be used with Devart's SimpleMembership provider.
I have very simple scenario where class A registers instances for types.
A.register(T1.class, new H1());
A.register(T2.class, new H2());
this is fairly simple configuration when done by hand but guice injection doesn't work when I create instances outside the guice framework.
I try to figure out how to create and configure A with all instance with custom annotation using guice.
I have found something like this Scan the classpath for classes with custom annotation but it is not using guice.
thanks
so I guess code.google.com/p/google-guice/wiki/Multibindings is the only option so far that works, but it is not as nice as I would expect since you need to connect everything by hand.