expression

How to use column value as select expression

本小妞迷上赌 提交于 2020-01-16 11:31:11
问题 There is a table that contains a column containing a SQL select expression. See the following example: ╔════╦════════╦═══════════════════════════════════════════╗ ║ ID ║ Code ║ Expression ║ ║ 1 ║ B12321 ║ SELECT * FROM table WHERE code LIKE '%' ║ ║ 2 ║ A35525 ║ SELECT * FROM table WHERE code = '1234' ║ ║ 3 ║ C23213 ║ SELECT * FROM table WHERE code <> '%D' ║ ╚════╩════════╩═══════════════════════════════════════════╝ I want to loop throught the Expression column, execute those statements and

Combine multiple expression to create a Linq selector expression

夙愿已清 提交于 2020-01-16 09:10:08
问题 I'm trying to dynamically build the select statement of a Linq query. I have a function like this: public Task<List<T>> RunQuery<T>( IQueryable<T> query, FieldSelector<T> fields, int pageNumber, int pageSize) { var skip = (pageNumber-1) * pageSize; var query = query.Skip(skip).Take(pageSize); var selector = fields.GetSelector(); return query.Select(selector).ToListAsync(); } Here is the FieldSelector class: (I my code I have extra properties per field) public class FieldSelector<T> { private

How to use the regex module in python to split a string of text into the words only?

别说谁变了你拦得住时间么 提交于 2020-01-15 12:49:28
问题 Here's what I'm working with… string1 = "Dog,cat,mouse,bird. Human." def string_count(text): text = re.split('\W+', text) count = 0 for x in text: count += 1 print count print x return text print string_count(string1) …and here's the output… 1 Dog 2 cat 3 mouse 4 bird 5 Human 6 ['Dog', 'cat', 'mouse', 'bird', 'Human', ''] Why am I getting a 6 even though there are only 5 words? I can't seem to get rid of the '' (empty string)! It's driving me insane. 回答1: Because while it splits based on the

validating the mobile numbers

≯℡__Kan透↙ 提交于 2020-01-15 09:32:06
问题 I need a regular expression to validate the mobile number up to 9 digits, if the telephone number starts with 8 otherwise 10 digits needs to be entered. The numbers must start either with 9 or 8 with above criteria. 回答1: ^(8\d{8}|[1-79]\d{9})$ 回答2: Not sure about the answer, but you should check out this very useful website for reg expressions incase you are interested: http://www.regexlib.com http://www.regexlib.com/CheatSheet.aspx 回答3: Use the following regular expression to match the phone

Nested Expression method call in Linq.Select()

喜欢而已 提交于 2020-01-15 08:20:25
问题 I use .Select(i=> new T{...}) after every db hit manually to convert my entity objects into DTO object. Here are some sample entities and DTOS User Entity; public partial class User { public int Id { get; set; } public string Username { get; set; } public virtual UserEx UserEx { get; set; } } User DTO; public class UserDTO { public int Id { get; set; } public string Username { get; set; } } UserEx entity; public class UserEx { public int UserId { get; set; } public string MyProperty1 { get;

Nested Expression method call in Linq.Select()

好久不见. 提交于 2020-01-15 08:19:28
问题 I use .Select(i=> new T{...}) after every db hit manually to convert my entity objects into DTO object. Here are some sample entities and DTOS User Entity; public partial class User { public int Id { get; set; } public string Username { get; set; } public virtual UserEx UserEx { get; set; } } User DTO; public class UserDTO { public int Id { get; set; } public string Username { get; set; } } UserEx entity; public class UserEx { public int UserId { get; set; } public string MyProperty1 { get;

How to use more than one expression in a row

本秂侑毒 提交于 2020-01-14 09:57:07
问题 I am new to R and I am trying to figure out, how to write something like "Hey guys, this is my plot for (\n)8 <=(less than or equal) x <= 10" in my plot-title. I tried something like this: plot(1:10, main="Hey, guys, this is my plot for \n") mtext(c(expression(8 <= x),expression(x <= 10), side=3) This gives not exactly what I want but "8 (less or equal) x x (less or equal) 10", and those two expressions are printed in a line below the main title, (which is pretty cool) but in the same place,

No generic method 'OrderBy' on type 'Queryable' is compatible with the supplied type arguments

﹥>﹥吖頭↗ 提交于 2020-01-14 09:32:15
问题 I'm writing some code that will modify an expression so that the subquery contained in it will get ordered. I found a similar piece of code here on SO, but it's not working for me. I also tried looking at this answer, but I'm not able to apply this to my piece of code No generic method 'OrderBy' on type 'Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. MethodCallExpression orderByCallExpression =

Create Expression<Func<T, object>> from a given Type

怎甘沉沦 提交于 2020-01-14 07:00:15
问题 I am looking to use CsvHelper dynamically by building up Expressions in code which represent property member access for a given type. The method I am trying to pass these expressions to has the following signature: public virtual CsvPropertyMap<TClass, TProperty> Map<TProperty>( Expression<Func<TClass, TProperty>> expression ) { // } So you would normally call it, for any given type you want to map, like this (for a type with a property called 'stringProperty'): mapper.Map(x => x

Create predicate with nested classes with Expression

跟風遠走 提交于 2020-01-12 02:27:23
问题 I have this : public class Company { public int Id { get; set; } public string Name { get; set; } } public class City { public int Id { get; set; } public string Name { get; set; } public int ZipCode { get; set; } } public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int? Age { get; set; } public City City { get; set; } public Company Company { get; set; } } I'd like a some case generate the predicate like this :