使用DapperExtensions进行谓词化(Predicate with DapperExtensions)
我试图用DapperExtensions创建一个通用的Find方法
这是我的方法
public IEnumerable<T> Find(Expression<Func<T, object>> expression) { using (IDbConnection cn = GetCn()) { cn.Open(); var predicate = Predicates.Field<T>(expression, Operator.Eq, true); return cn.GetList<T>(predicate); } }
但是我在这行上得到了
System.NullReferenceException
var predicate = Predicates.Field<T>(expression, Operator.Eq, true);
这是来自DapperExtensions帮助文档但我尝试将其转换为Generic方法。
using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true); IEnumerable<Person> list = cn.GetList<Person>(predicate); cn.Close(); }
Im trying to make a generic Find method with DapperExtensions
This is my method
public IEnumerable<T> Find(Expression<Func<T, object>> expression) { using (IDbConnection cn = GetCn()) { cn.Open(); var predicate = Predicates.Field<T>(expression, Operator.Eq, true); return cn.GetList<T>(predicate); } }
But i get
System.NullReferenceException
on this rowvar predicate = Predicates.Field<T>(expression, Operator.Eq, true);
This is from the DapperExtensions help documentation But I try convert this to a Generic method.
using (SqlConnection cn = new SqlConnection(_connectionString)) { cn.Open(); var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true); IEnumerable<Person> list = cn.GetList<Person>(predicate); cn.Close(); }
原文:https://stackoverflow.com/questions/14585212
最满意答案
通过用fig = plt.figure()替换fig = plt.figure(1)解决了这个问题。dataframe问题也可以通过全局读取csv并每次过滤该数据帧来解决。
Solved the problem by replacing fig = plt.figure(1) with fig = plt.figure() dataframe problem is also solved by reading the csv globally and filter that dataframe every time.
相关问答
更多-
查找熊猫dataFrame(Looking up Pandas dataFrame)[2022-04-17]
您可以使用isin使用boolean indexing : array=['A34579','B943470','D583730'] print (df[df.analyte_id.isin(array)]) analyte_id mass Intensity 0 A34579 101.20 786788 2 B943470 103.89 986443 另外如果只需要一些列使用ix : array=['A34579','B943470','D583730'] ... -
如何改变DataFrame?(How to Mutate a DataFrame?)[2023-09-27]
据我所知,朱莉娅使用所谓的共享传递,这意味着引用是通过值传递的。 因此,当您将DataFrame传递给函数时,会创建一个对函数本地的DataFrame的新引用。 当您使用自己对DataFrame的引用重新分配本地df变量时,它对单独的全局变量及其对DataFrame的单独引用没有影响。 DataFrames.jl中有一个用于删除DataFrames中的列的函数。 As I understand Julia it uses what is called pass by sharing, meaning tha ... -
sqlContext.createDataFrame(PANDASDATA) sqlContext.createDataFrame(PANDASDATA)
-
做 donor_age = int(input("Enter Donor's Age: ")) input()返回一个字符串,它看起来像你正在comapring一个字符串与int不能比较。 将输入转换为int或float,或将另一个时间转换为str。 Do donor_age = int(input("Enter Donor's Age: ")) input() returns a string, it looks like you are comapring a string with a int w ...
-
感谢Bob Haffner ,仔细观察文档,DataFrame根本不是问题,而是我传递的X和Y参数。 当我本来应该传递字符串时,我正在传递系列,如下: sns.lmplot("Length of Membership", "Yearly Amount Spent", customers) Thanks to Bob Haffner, looking closer at the documentation, the DataFrame wasn't the issue at all, rather, the ...
-
确实有: type(df.iloc[:,[0]]) 将列/列作为列表传递,并返回数据帧。 你可以看到差异: In [288]: df = pd.DataFrame({0 : [1, 2, 3], 1: [3, 4, 5], 2:[4, 5, 6]}); df Out[288]: 0 1 2 0 1 3 4 1 2 4 5 2 3 5 6 In [289]: df.iloc[:, 0] Out[289]: 0 1 1 2 2 3 Name: 0, dtyp ...
-
从Pandas DataFrame调用列数据时出现Python错误(Python error when calling column data from Pandas DataFrame)[2023-11-17]
此CSV文件包含BOM(字节顺序标记)签名 ,因此请尝试这种方式: df = pd.read_csv(path, encoding='utf-8-sig') 如何轻松识别这个问题(感谢@ jezrael的提示 ): In [11]: print(df.columns.tolist()) ['\ufeffDate', 'Open', 'High', 'Low', 'Close', 'Volume'] 并注意第一栏 注意:正如@ayhan注意到的那样,从版本0.19.0开始, Pandas会自动处理它 : ... -
通过用fig = plt.figure()替换fig = plt.figure(1)解决了这个问题。dataframe问题也可以通过全局读取csv并每次过滤该数据帧来解决。 Solved the problem by replacing fig = plt.figure(1) with fig = plt.figure() dataframe problem is also solved by reading the csv globally and filter that dataframe every ...
-
df.lookup期望2个数组(而不是标量)作为参数: In [25]: df.lookup(row_labels=[DT.datetime(2011,1,10,16,0)], col_labels=['AAPL']) Out[25]: array([ 340.99]) 如果您只想查找一个值,请改用df.get_value : In [30]: df.get_value(DT.datetime(2011,1,10,16,0), 'AAPL') Out[30]: 340.99000000000001 df ...
-
如果你想在没有observeEvent情况下这样做,你可以这样做: data <- as.data.frame(c(98,99,34)) names(data) <- "Projection" data$User_Prediction <- 0 ui <- shinyUI( fluidPage( titlePanel("Basic DataTable"), # Create a new row for the table. fluidRow( column(1 ...