Firstly, thank you for this awesome database. It is very simple to understand for anyone who knows Relational model. I can see myself modelling data in graph for all future projects.
Now the question,
I am trying to use OrientDB for data modelling and I faced a strange issue. The field names in the queries uses case sensitivity arbitarily.
For example,
SELECT FROM appuser WHERE mobile = '1111111111' AND out('userhasrole').rolename CONTAINS 'user'
and
SELECT FROM appuser WHERE MOBILE= '1111111111' AND out('userhasrole').rolename CONTAINS 'user'
works perfectly fine.
But
SELECT FROM appuser WHERE mobile = '1111111111' AND out('userhasrole').ROLENAME CONTAINS 'user'
and
SELECT FROM appuser WHERE MOBILE= '1111111111' AND out('userhasrole').ROLENAME CONTAINS 'user'
doesn't work
Notice that it doesn't work if "rolename" does not match the exact field name. Could you please suggest if this is normal?
Another thing, probably more important is
SELECT FROM appuser WHERE MOBILE= '1111111111' AND out('userhasrole').rolename CONTAINS 'user'
works, but
SELECT FROM appuser WHERE MOBILE= '1111111111' AND out('userhasrole').rolename ='user'
doesn't work. the field "rolename" is a simple string but still I have to use CONTAINS for it to work. Please advice on this too.
Please let me know if I have missed anything.
Thanks!
1° Answer
SELECT FROM appuser WHERE mobile = '1111111111' AND out('userhasrole').ROLENAME CONTAINS 'user'
and
SELECT FROM appuser WHERE MOBILE= '1111111111' AND out('userhasrole').ROLENAME CONTAINS 'user'
they don't work beacuse of the property ROLENAME written in uppercase. OrientDB is case sensitive and you have to write the name of the properties correctly, expecially if you are in a where condition.
2° Aswer
The fact to use contains instead of ' = ' is because the property rolename could be a list, so, it can contains a lot of data, for this reason you have to use CONTAINS.
Hope it helps
Related
I have a model called User and each user has a list of another model called Hobbies. I want to retrieve a User who has a hobby with a certain ID, is there anything better using Entity Framework than just retrieving all users then searching inside each user's hobbies list and match it with the hobby id, a pseudo code would look like the following
UserList = select all users from db
targetUser = null;
for User in UsersList:
for Hobby in User.HobbiesList:
if(Hobby.ID == currentHobby.ID)
{
targetUser = User;
}
First of all, EF won't automatically get all the linked entities, you need to explicitly Include everything you want to see in the end result.
As for the question, yes of course, you can use all the standard LINQ filters when working with EF. In your case
db.Userlist.Where(user => user.HobbiesList.Any(hobby => hobby.ID == currentHobby.ID))
Don't forget to Include(user => user.HobbiesList) if you want to see it in the results.
How or where does moodle store how a parent/mentor is related to a student. I don't see how the system is tying the user and role assignment and whatever else it's using (context, etc).
I jut want to be able to query for a list of users who have supervisor/parent role and get their corresponding students.
Thanks
I assume you have configured the parent role as defined here: https://docs.moodle.org/en/Parent_role
If so, the connection is as follows:
Each user has a 'context' record, related to their userid. This can be retrieved via context_user::instance($userid) or from the database by
SELECT *
FROM mdl_context
WHERE instanceid = [userid] AND contextlevel = 30
(Where 30 is CONTEXT_USER and assuming your DB prefix is the default 'mdl_')
Parent/mentors have an appropriate role assigned to them at this user's context.
You can find this in the database by the following query:
SELECT userid
FROM mdl_role_assignments
WHERE contextid = [usercontextid]
Optionally, this could be restricted to only retrieve specific roleids (with "AND roleid = [parentroleid]"). However, most sites will only have parent/mentor roles assigned in the user context, so you can probably get away without checking the roleid.
The following query will perfectly answer your parent child relationship.
This query will return the parent id when you will pass the child id in query
SELECT userid as parent FROM mdl_role_assignments
join mdl_context on mdl_context.id = mdl_role_assignments.contextid
where mdl_context.contextlevel = 30 and mdl_context.instanceid = 162
here 162 is the child id
I need to get the list of all courses available with their username who created it in moodle site programmatically from database. As I am using drupal with moodle. In drupal I connected the moodle database so I need to fetch the courses with username for further development. Please help me on this.
Regards
Neha Singhania
The only place where you can find out who created a course is in the mdl_log table. Look for an entry with module = course and action is something like 'create' (I haven't got the code in front of me right now to check). The 'course' field will match the id of the mdl_course table, where you can find the course name (fullname / shortname). The user field will match the id of the mdl_user table, where you can find the firstname, lastname and username for the user.
I have two models, User and Class. In MySQL, I could find users not in a class with something like:
SELECT * FROM Users WHERE id NOT IN (SELECT user_id FROM Classes)
How can I do something similar with MongoMapper? I've been able to in the Mongo console with:
db.users.find({user_id:{$ne:db.classes.find({}, {user_id:1})}});
but I can't figure out the syntax using MongoMapper.
The Mongo snippet you posted is two queries. The MongoMapper equivalent is:
classy_users_ids = MyClass.fields(:user_id).find_each.map(&:user_id).uniq
classless_users = User.where(:id.nin => classy_users_ids)
If you have a lot of users, the first query might be more efficient if you skip the conversion to MongoMapper::Document's with the following:
classy_users_ids = MyClass.collection.distinct(:user_id)
If they are related like Class ... has_many :users you can match directly against user_ids:
Class.where(:user_ids.ne => user.id)
I was wondering with Entity Framework 4.1 code first how do you guys handle queries that involve an existing aspnet_Users table?
Basically I have a requirement for a query that involves the aspnet_Users so that I can return the username:
SELECT t.Prop1, u.Username
FROM Table1 t
INNER JOIN aspnet_User u ON t.UserId = u.UserId
Where t.Prop2 = true
Ideally in linq I would like:
from t in context.Table1
join u in context.aspnet_Users on t.UserId equals u.UserId
where t.Prop2 = true
But I'm not sure how to get aspnet_Users mapping to a class User? how do I make aspnet_Users part of my dbset ?
Any help would be appreciated, thanks in advance
Don't map aspnet_Users table or any other table related to aspnet. These tables have their own data access and their own logic for accessing. Mapping these tables will introduce code duplication, possible problems and breaks separation of concerns. If you need users for queries, create view with only needed information like id, user name, email and map the view. The point is that view will be read only, it will contain only allowed data and your application will not accidentally modify these data without using ASP.NET API.
First read Ladislav's answer. If you still want to go ahead : to do what you want would involve mapping the users and roles and members tables into the codefirst domain - which means writing a membership provider in code-first.
Luckily there is a project for that http://codefirstmembership.codeplex.com/ although its not a perfect implementation. The original is VB, look in the Discussion tab for my work on getting it running in c# MVC.
I'm working with the author on a better implementation that protects the membership data (password, last logged on date, all of the non-allowed data) but allow you to map and extend the user table. But its not ready yet!
You don't really need to use Entity Framework to access aspnet_membership provider accounts. You really just need to create an instance of the membership object, pass in a unique user identifier and a Boolean value indicating whether to update the LastActivityDate value for the user and the method returns a MembershipUser object populated with current values from the data source for the specified user.
You can then access the username by using the property of "Username".
Example:
private MembershipUser user =
Membership.GetUser(7578ec40-9e91-4458-b3d6-0a69dee82c6e, True);
Response.Write(user.UserName);
In case you have additional questions about MembershipProvider, you can read up on it on the MSDN website under the title of "Managing Users by Using Membership".
Hope this helps you some with your requirement.