小编f0s*_*ter的帖子

LINQ的查询扩展

我有一些代码用于在linq中强类型Includes(),就像这样......

public static ObjectQuery<T> Include<T>(this ObjectQuery<T> mainQuery, Expression<Func<T, object>> subSelector)
    {
        return mainQuery.Include(((subSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name);
    }

    /// <summary>
    /// Old way: (from dbUser in DataSource.DataContext.Users.Include("UserSubscriptions.ChurchSubscriptions") select dbUser);
    /// New way: (from dbUser in DataSource.DataContext.Users.Include<Users, UserSubscriptions>(u => u.UserSubscriptions, s => s.ChurchSubscriptions) select dbUser);
    /// </summary>
    public static ObjectQuery<T> Include<T, Q>(this ObjectQuery<T> mainQuery, Expression<Func<T, object>> tSubSelector, Expression<Func<Q, object>> qSubSelector)
    {
        string tProperty = ((tSubSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name;
        string qProperty = ((qSubSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name;
        string path = string.Format("{0}.{1}", …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-entities

5
推荐指数
1
解决办法
419
查看次数

在相关模型更新销毁之前,错误不会传播

我有一个父模型,正在通过诸如'@ client.update_attributes(params [:client]'之类的参数进行更新.在我的参数中是一个销毁'client_card'的调用.我在client_card上有一个before_destroy方法来阻止它我的before_destroy方法正在运行,但是,更新时,before_destroy上的错误不会传播到相关模型.有关如何在更新时将此模型错误传播到关联模型的任何建议吗?

class Client < ActiveRecord::Base
  has_many :client_cards, :dependent => :destroy
  validates_associated :client_cards

class ClientCard < ActiveRecord::Base
  belongs_to :client, :foreign_key => 'client_id'

  attr_accessible :id, :client_id, :card_hash, :last_four, :exp_date

  before_destroy :check_relationships

  def check_finished_appointments
    appointments = Appointment.select { |a| a.client_card == self && !a.has_started }
    if(appointments && appointments.length > 0 )
      errors.add(:base, "This card is tied to an appointment that hasn't occurred yet.")
      return false
    else
      return true
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails

5
推荐指数
1
解决办法
710
查看次数

没有src属性的iframe上的Chrome扩展程序内容脚本

我有一个内容脚本,它将iframe注入到我的页面的DOM中.这个iframe没有src属性,我用它的内容动态创建它...

iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
Run Code Online (Sandbox Code Playgroud)

如何在此iframe上运行我的内容脚本?或者与后台沟通?我需要从此代码中触发"关闭我的iframe"事件.我知道这是可能的,因为亲爱的就是这样做的.

https://chrome.google.com/webstore/detail/honey/bmnlcjabgnpnenekpadlanbbkooimhnj?hl=en-US

html javascript iframe google-chrome-extension

0
推荐指数
1
解决办法
1022
查看次数