I am developing an application to search tweets by a hashtag and get tweet coordinates and put it on google maps. The result I am getting contains empty geo field. I searched alot on Stackoverflow and Twitter community about this but getting empty geo & coordinates for all tweets. Even though I tweet with my location open but still getting empty fields.
...
public 'geo' => null
public 'coordinates' => null
public 'place' => null
public 'contributors' => null
public 'is_quote_status' => boolean false
public 'retweet_count' => int 0
public 'favorite_count' => int 0
public 'entities' =>
Related
I have a user entity like this
#Entity()
export class User extends BaseEntity {
#OneToMany(() => UserLikePost, (userLikePost) => userLikePost.post)
likedPosts: UserLikePost[];
}
and post entity like this
#Entity()
export class Post extends BaseEntity {
#ManyToMany(() => User, (user) => user.likedPosts)
likedUsers: User[];
}
and bridge entity like this
#Entity()
export class UserLikePost extends BaseEntity {
static random() {}
#Column({
type: 'boolean',
})
isLike: boolean;
#ManyToOne(() => User, (user) => user.likedPosts)
user: User;
#ManyToOne(() => Post, (post) => post.likedUsers)
post: Post;
}
So basically I have a bridge entity between user and post that stores isLike column that decides if a user has like the post or not.
the list query works fine for example I can do
postRepository.find({
relation: ['likedUsers']
})
and I get list of corresponding UserLikePosts.
However, what I would really like to do is to get a list of posts in whatever order and add a boolean field to each post showing whether a specific user has liked the post or not.
Now I could just load all UserLikePost rows and filter the whether the user exists in the list but it seems like a huge waste of memory. I would like the query to be run in the DB and return only the boolean result whether the liked user exists in the UserLikePost table for target post.
How do I perform this query using typeorm?
If you'd like to get all posts that specific user liked, you can use nested where, i.e.
userLikePostRepository.find({
where: {
isLike: true,
user: {
id: <userId>,
},
},
relation: ['post']
})
I have a mongo-backed contact database in rails. I am doing reports that reports multiple checkbox using a filter.
For example:
I am using checkbox filter
Table name is Conversion
Columns in Conversion table are: browser, date, city, state, country, network, language
I am selecting date, city for filter, after filtering grouping should occur, based on the filter
Note: first filter next only grouping
Sometimes: date, city, country for filter, it will depends on the user
I have done this code only
Conversion.collection.aggregate([
{ "$match" => {
"date" => { '$gte' => start_date, '$lte' => end_date }
}
},
{ "$group" => {
"_id" => {
"country" => "$country",
"city" => "$city",
"browser" => "$browser",
"network" => "$network",
"language" => "$language"
}
}
},
])
But this code is grouping all columns every time. I want the checkbox selected column only grouping to occur. For that how do I write the grouping code? Can anyone suggest any idea?
Let's say I have a table - UserToChannel_tbl which has following fields - Id, UserId and ChannelId. I am deriving EntityTypeConfiguration and putting all properties in that as below (example) -
public class UserToChannelConfiguration : EntityTypeConfiguration<UserToChannel>
{
public UserToChannelConfiguration(){
HasKey(p => p.Id);
Property(p => p.Id)
.HasColumnName("Id")
.HasDatabaseGeneratedOption((DatabaseGeneratedOption?) DatabaseGeneratedOption.Identity)
.IsRequired();
Property(p => p.UserId)
.HasColumnName("UserId").IsRequired();
HasRequired(p => p.User).WithMany().HasForeignKey(t => t.UserId);
Property(p => p.ChannelId)
.HasColumnName("ChannelId").IsRequired();
HasRequired(p => p.Channel).WithMany().HasForeignKey(t => t.ChannelId);
}
}
Now, the table already has clustered index on Id column, but I also need a non-clustered index on UserId, ChannelId column. Is there a way to achieve this here instead of doing this in Migration class or anywhere else. Seems much simpler to me if I can define all my properties at one place. I am using ASP.NET MVC 4 with EF6.
EF still cant do indexes so migrating SQL such as
CREATE NONCLUSTERED INDEX [IX_User_u_username] ON [dbo].[BlockedUsers] ([User_u_username])
is not going to happen.
The migration tool for code first is fine for the general cases, not the edge cases it seems.
I am a complete beginner in MVC3 and web development in general.
My client database uses unique candidate key of one table as foreign key of another. I cannot change the way the database is designed whatsoever. I have models derived from the database tables. I know that Entity Framework does not support candidate key as foreign key of another table.
So my question is, how do professionals work around this limitation of the entity framework?
Since current versions of EF require FKs to point to PKs, it's not an easy problem to overcome.
One technique I've used is (with EF CodeFirst...er...Second) to override the PKEY in the Parent table's mapping and specify an anonymous type instead.
public class ParentObject
{
public int Id {get; set;} //the actual PKEY in the Db
public string CandidateKey1 {get;set;}
public string CandidateKey2 {get;set;}
public string CandidateKey3 {get;set;}
public virtual ICollection<ChildObject> ChildObjects {get;set;}
}
public class ChildObject
{
public int Id {get; set;}
public string CandidateKey1 {get;set;}
public string CandidateKey2 {get;set;}
public string CandidateKey3 {get;set;}
public virtual ParentObject ParentObject {get;set;}
}
In order for this to work, you'll need to specify that the Parent table's PKEY is an anonymous object rather than the PKEY actually stored in the DB.
public ParentObjectMap()
{
// Primary Key
//this.HasKey(t => t.Id); //override this as PKEY for EF purposes
this.HasKey(t => new { t.CandidateKey1, t.CandidateKey2, t.CandidateKey3 });
// Table & Column Mappings
this.ToTable("ParentTable");
this.Property(t => t.Id).HasColumnName("ParentId");
this.Property(t => t.CandidateKey1).HasColumnName("Key1");
this.Property(t => t.CandidateKey2).HasColumnName("Key2");
this.Property(t => t.CandidateKey3).HasColumnName("Key3");
}
and the child object map
public ChildObjectMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Table & Column Mappings
this.ToTable("ChildTable");
this.Property(t => t.Id).HasColumnName("ChildId");
this.Property(t => t.CandidateKey1).HasColumnName("Key1");
this.Property(t => t.CandidateKey2).HasColumnName("Key2");
this.Property(t => t.CandidateKey3).HasColumnName("Key3");
this.HasRequired(t => t.ParentObject)
.WithMany(t => t.ChildObjects)
.HasForeignKey(t => new { t.CandidateKey1, t.CandidateKey2, t.CandidateKey3 });
}
Of course, this introduces other problems such as uniqueueness of the actual Parent Id property which you'll need to deal with in implemented code. However, this technique has gotten the job done for me when writing code against a similar (candidate keyed) Progress 4GL OpenEdge -> MSSQL db over which I had no control.
It's also not nearly as fast as native EF -> MSSQL mappings which take advantage of FK relationships in the DB.
I am having some problem setting the Identity Seed on the Id column in SQL Compact 4 using the code first approach.
I have tried this
context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Members', RESEED, 100001");
but this is not working in Sql Compact.
MyDbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
SetupMemberEntity(modelBuilder);
}
private static void SetupMemberEntity(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Member>().Property(m => m.Id);
//.Property(m => m.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Member>().Property(m => m.FirstName).IsRequired();
modelBuilder.Entity<Member>().Property(m => m.LastName).IsRequired();
modelBuilder.Entity<Member>().Property(m => m.PinCode).IsRequired();
modelBuilder.Entity<Member>().Property(m => m.Email);
//modelBuilder.Entity<Member>().Property(m => m.DateCreated).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
//modelBuilder.Entity<Member>().Property(m => m.DateModified).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}
I have added one more property MemberId to the Member entity and have tried to use
context.Database.ExecuteSqlCommand("ALTER TABLE Members ADD MemberId INT IDENTITY(10000,1) PRIMARY KEY");
but I get error message that a table can only contain one identity, but I havent set any IDENTITY so, is the Id column auto IDENTITY ?
I found the answer here:
context.Database
.ExecuteSqlCommand("ALTER TABLE Members ALTER COLUMN Id IDENTITY (10000,1)");
To set the first seed value for an Identity column using Entity Framework:
builder.Property(prop => prop.Id)
.UseIdentityColumn(10000000, 1);
from here.