小编Lau*_*hey的帖子

LINQ to EF - 查找子集合的字符串属性至少部分匹配字符串列表中的所有记录的记录

我目前正在使用LINQ和Entity Framework 5.0编写基于Web的"配方"应用程序.我一直在努力解决这个问题,所以任何帮助都非常感谢!

将有一个搜索功能,用户可以在其中输入他们希望配方结果匹配的成分列表.我需要找到所有配方,其中关联的成分集合(名称属性)包含字符串列表中的每个记录的文本(用户搜索术语).例如,请考虑以下两个配方:

Tomato Sauce: Ingredients 'crushed tomatoes', 'basil', 'olive oil'
Tomato Soup:  Ingredients 'tomato paste', 'milk', 'herbs
Run Code Online (Sandbox Code Playgroud)

如果用户使用搜索术语'番茄'和'油',它将返回番茄酱而不是番茄汤.

var allRecipes = context.Recipes
                .Include(recipeCategory => recipeCategory.Category)
                .Include(recipeUser => recipeUser.User);

IQueryable<Recipe> r = 
from recipe in allRecipes
let ingredientNames = 
    (from ingredient in recipe.Ingredients 
     select ingredient.IngredientName)
from i in ingredientNames
let ingredientsToSearch = i where ingredientList.Contains(i)
where ingredientsToSearch.Count() == ingredientList.Count()
select recipe;
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

var list = context.Ingredients.Include(ingredient => ingredient.Recipe)
       .Where(il=>ingredientList.All(x=>il.IngredientName.Contains(x)))
       .GroupBy(recipe=>recipe.Recipe).AsQueryable();
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

linq entity-framework entity-framework-5

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

使用'dd-slick'jQuery插件对链式下拉菜单进行样式化会破坏数据的自动更新

我正在使用jquery.ddslick.min.jsjQuery插件来创建带有选项图像的风格化下拉框.我还jquery.chained.min.js用于根据第一个下拉列表中选择的值自动更新第二个选择框中的数据.

我的要求是:

  • 样式化下拉框以允许在选项中使用图像
  • 根据第一个选项中选择的选项自动更新第二个下拉框中的数据.
  • 触发显示所选选项值的警报
  • 提供下拉框的滚动功能

目前,当我在第一个选项中选择一个选项时,第二个选择框中的项目不会更新.选择一个选项时,我也无法触发警报; 滚动功能也无法正常工作.

HTML:

<select id="inames">
    <option value="">-slect place-</option>
    <option value="Utilities">Utilities</option>
    <option value="Emergency Services">Emergency Services</option>
    <option value="General">General</option>
</select> 

<select id="ddslicks" >
    <option data-imagesrc="../css/PoiImages/airport.png" class="Utilities" value="airport"></option>
    <option data-imagesrc="../css/PoiImages/ambulance.png" class="Utilities" value="ambulance"></option>
    <option data-imagesrc="../css/PoiImages/atm.png" class="General" value="atm"></option>
    <!-- _  _  etc -->
</select>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

$("#ddslicks").chainedTo("#inames"); /* or $("#series").chainedTo("#mark"); */
Run Code Online (Sandbox Code Playgroud)

添加警报时,我也会遇到问题.

alert($('#ddslicks').val())
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-plugins

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

将 JTA、Hibernate 4 和 Spring 4 与 WebLogic 集成

我在实现 JTA/Hibernate/Spring 应用程序(服务器使用 WebLogic 10.3)时遇到了严重的问题。我最初使用的是 Spring 编程配置,但已将其移至 Spring XML 配置以过滤潜在问题。当我使用 HibernateTransactionManager 而不是 JtaTransactionManager 时,它工作得很好,但现在没有找到线程的会话。

当我查看 sessionFactory 时,它不为 null,但 getSession() 不返回会话。

你能帮我解决这个问题吗?谢谢!

我的道实现:

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

...

import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import mil.navy.navsupbsc.utilities.HibernateConfiguration;

@Repository
public class ContactDAOImpl implements ContactDAO {

    @Autowired
    SessionFactory sessionFactory;

    public Session getSession() {
        try {
            sessionFactory.openSession();
            return sessionFactory.getCurrentSession();
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw e;
        }

    }

@SuppressWarnings("unchecked")
public List<Contact> listContact() {

    List<Contact> …
Run Code Online (Sandbox Code Playgroud)

spring hibernate weblogic jta

3
推荐指数
1
解决办法
7352
查看次数