我是约束编程的初学者,我在我的 c# 程序中使用Google or-tools 库。
我想向我的求解器添加以下约束:
((t1 >= 12 && t1 <= 15) || (t2 >= 16 && t2 <= 18)) && ( t1 + t2 ) < 30
所以我用c#写了下面一段代码:
var solver = new Solver("My_CP_Colver");
var t1 = solver.MakeIntVar(12, 20,"t1");
var t2 = solver.MakeIntVar(12, 20,"t2");
solver.Add(???)//<-((t1 >= 12 && t1 <= 15)||(t2 >= 16 && t2 <= 18)) && ( t1 + t2 ) < 30
Run Code Online (Sandbox Code Playgroud)
请帮助做出上述限制?
我的WCF服务使用wsHttpBinding,当客户端使用默认选项对服务进行gerenated时,客户端可以正常工作,如下所示:
RServiceClient R = new RServiceClient();
Run Code Online (Sandbox Code Playgroud)
但是,在某些时候,我需要能够指定服务的位置,可能是通过更改端点地址,如下所示:
RServiceClient R = new RServiceClient();
R.Endpoint.Address = new EndpointAddress(new Uri "http://xxx.xxxx.xxx:80/RServer/RService.svc"));
Run Code Online (Sandbox Code Playgroud)
但是,当我确实指定了确切的端点时,我得到一个SecurityNegotiationException:System.ServiceModel.Security.SecurityNegotiationException未处理Message ="调用者未被服务验证." 来源= "mscorlib程序" ....
WCF服务在IIS上运行,并在IIS管理员下启用了匿名访问.此外,当客户端从与管理员帐户下的服务相同的计算机运行时,会发生此错误 - 我还没有到达通过网络运行它的可怕部分!
有任何想法吗?
我Form
在我的WinForm
应用程序中有一个包含a TextBox
和this TextBox
绑定到Object的FirstName
属性Person
.
public class Person
{
string firstName;
public string FirstName
{
get { return firstName; }
set {
firstName = value;
this.isOdd = value.Length % 2;
}
}
bool isOdd;
public bool IsOdd { get {return isOdd; } }
}
Run Code Online (Sandbox Code Playgroud)
当我的应用程序运行时,这个Form
节目和用户可以键入他/她的名字的文本框,我如何绑定BackColor
的属性Form
的IsOdd
的属性Person
对象(当IsOdd
被True
BackColor
设置为Color.Green
当它是False
将BackColor
设置为Color.Red
)?
我有一个界面:
public interface IMessager
{
void ShowMessage();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使用扩展方法实现此接口?
public static class Extensions
{
public static void ShowMessage(this MyClass e)
{
Console.WriteLine("Extension");
}
}
Run Code Online (Sandbox Code Playgroud)
以及实现它的类:
public class MyClass:IMessager
{
public void ShowMessage()
{
ShowMessage(); // I expect that program write "Extension" in console
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行程序时,我得到了System.StackOverflowException
.
我有以下表达方式
Expression<Func<T, object>> expr1;
有没有办法把它投入
Expression<Func<IUpdateConfiguration<T>, object>>
?
[更新]
或者Expression<Func<IUpdateConfiguration<T>, object>>
从现有的新建Expression<Func<T, object>>
?
我的 EF 代码第一个模型中的所有实体都有以下抽象基类:
public abstract class BaseEntity
{
public Id {get; set;}
public bool IsDeleted {get; set;}
...
}
Run Code Online (Sandbox Code Playgroud)
我在我DbContext
的OnModelCreating()
方法中编写了以下代码来忽略IsDeleted
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
...
modelBuilder.Types().Configure(c => c.Ignore("IsDeleted"));
...
}
Run Code Online (Sandbox Code Playgroud)
但是当它导致以下错误时:
您不能在类型“MyEntity”上的属性“IsDeleted”上使用忽略方法,因为此类型继承自映射此属性的类型“BaseEntity”。要从模型中排除此属性,请在基类型上使用 NotMappedAttribute 或 Ignore 方法。
我正在使用.NET 4
所以我不能[NotMappedAttribute]
用来 ignore IsDeleted
,所以我使用了以下代码:
public partial class BaseEntity_Mapping : EntityTypeConfiguration<BaseEntity>
{
public BaseEntity_Mapping()
{
this.HasKey(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Ignore(t => t.IsDeleted);
}
}
Run Code Online (Sandbox Code Playgroud)
并将OnCreatingModel()
方法更新为:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
... …
Run Code Online (Sandbox Code Playgroud) 我想在删除实体时捕获外键异常。但是EF仅引发自定义异常。我需要检查是否存在外键冲突,而无需通过EF“手动”检查所有关系。
try
{
applicationDbContext.SaveChanges();
// even though debugger shows an SqlException at first, it doesnt get caught but an DBUpdateException is thrown...
return RedirectToAction("Index");
}
catch (System.Data.SqlClient.SqlException ex)
{
if (ex.Errors.Count > 0)
{
switch (ex.Errors[0].Number)
{
case 547: // Foreign Key violation
ModelState.AddModelError("CodeInUse", "Country code could not be deleted, because it is in use");
return View(viewModel.First());
default:
throw;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我知道在单击后如何隐藏“提交”按钮方面有很多答案,但是我无法使用任何解决方案。我试图用onclick=""
和javascript 隐藏它。该表格适用于wordpress插件。
echo '<p><input type="submit" name="submitted" id="send" value="Send"></p>';
Run Code Online (Sandbox Code Playgroud) 我必须遵循以下课程:
public class NominalValue
{
public int Id {get; set;}
public string ElementName {get; set;}
public decimal From {get; set;}
public decimal To {get; set;}
public bool Enable {get; set;}
public DateTime CreationDate {get; set;}
public int StandardValueId {get; set;} //FK for StandardValue
}
public class StandardValue
{
public int Id {get; set;}
public string ElementName {get; set;}
public decimal From {get; set;}
public decimal To {get; set;}
public bool Enable {get; set;}
public DateTime CreationDate {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
用户想要填充 …
我有以下代码:
public class MyClass<T>
{
Expression<Func<T,bool>> Criteria {get; set;}
}
public class Customer
{
//..
public string Name {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
并使用如下:
var c = new MyClass<Customer>();
c.Criteria = x.Name.StartWith("SomeTexts");
Run Code Online (Sandbox Code Playgroud)
有没有办法定义这样的东西:
? p = x=>x.Customer.Name;
var c = new MyClass<Customer>();
c.Criteria = p => p.StartWith("SomeTexts");
Run Code Online (Sandbox Code Playgroud)
我Expression<Func<T,bool>>
以前在linq to entities
查询中使用它作为where子句(EF代码优先).