我有以下连接字符串:
<?xml version="1.0" encoding="utf-8"?>
<connectionStrings>
<add name="MyContext" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='data source=SQLSERVERDB;initial catalog=TestDB_CodeFirst;user id=***;password=***;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我尝试启用迁移时,我首先收到警告:
无法确定有效的启动项目。改用项目“MyApp.Model”。
您的配置文件和工作目录可能未按预期设置。
使用 -StartUpProjectName 参数明确设置一个。
然后我得到这个异常:
参数“xmlReader”无效。必须至少提供一个 .ssdl 工件。
连接字符串是否错误?如果我使用 Code First,为什么还需要 ssdl?
笔记
MyApp.Model在我的Migrations文件夹应该位于的项目中。MyApp.Model它指向我的开发数据库。另外,我的第二个问题是:
如果我使用 CF 迁移,每次用户第一次选择不同的数据库时,是否会迁移所有数据库?
编辑
我更改了如下所述的连接,但出现以下异常:
元数据集合中已存在标识为“table1”的项目。参数名称:项目
必须指出的是,我对现有数据库进行了逆向工程。所以我不知道可能出了什么问题!
我还删除了 Migrations 文件夹并检查了数据库,但没有创建 migration_history 表。
我有一个项目列表,我需要循环它,以便首先收集每个n(例如3)项目,然后在第n项目处立即处理.
我正在做以下事情:
List<MyObject> smallList = new List<MyObject>();
for (int i = 0; i < largeList.Count; i++)
{
smallList.Add(largeList[i]);
if (i % 3 == 0 || i >= largeList.Count - 3)
{
//Do somehting with those n items...
}
smallList.Clear();
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点?
我正在学习WPF,我正在尝试使用一个由顶部的工具栏组成的表单,底部的状态栏,其余的将由用于数据输入的控件占用.
这是我到目前为止:
<Window x:Class="MyApp.MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyForm" Height="346" Width="459">
<DockPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="New" Content="New" />
<Button Command="Open" Content="Open" />
<Button Command="Save" Content="Save" />
</ToolBar>
</ToolBarTray>
</DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
如何在底部添加状态栏,以及将占用表单其余部分的另一个面板?
我有以下正则表达式模式:
"[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}"
Run Code Online (Sandbox Code Playgroud)
我想验证具有以下条件的字符串
但是,上述模式不起作用.需要改变什么?
我正在使用Dapper的Query <>来搜索许多记录:
public class Product
{
public int Id {get; set}
public string Name {get; set}
public int CategoryId {get; set}
]
public IEnumerable<Product> GetProducts(int categoryId)
{
var connection = DataContext.Database.Connection;
var sql = "SELECT * FROM products WHERE category_id = @categoryId";
var result = connection.Query<Product>(sql, new { categoryId });
return result;
}
Run Code Online (Sandbox Code Playgroud)
查询本身返回请求的记录,但列表中的每个对象都有空字段.
那么如何将列映射到实体的属性?
我不想在sql语句中添加列别名.装饰实体的属性也不是一种选择,因为实体是由EF设计者生成的.
我有一个从基本形式继承的表单.在baseform_load和childform_load事件中都有代码.
BaseForm看起来像这样:
public partial class BaseForm : Form
{
public BaseForm()
{
InitializeComponent();
}
private void BaseForm_Load(object sender, EventArgs e)
{
//Do stuff...
}
}
Run Code Online (Sandbox Code Playgroud)
并且子表单可能如下所示:
public partial class ChildForm : BaseForm
{
public ChildForm ()
{
InitializeComponent();
}
private void ChildForm _Load(object sender, EventArgs e)
{
//Do stuff...
}
}
Run Code Online (Sandbox Code Playgroud)
在baseformLoad事件没有被明确载入.事件处理程序也可用,因为它们是通过表单设计器创建的.
我用以下方法打开表单:
public static DialogResult ShowForm<T>(this Form form, bool canShowForm) where T : Form, new()
{
return new T().ShowDialog(form);
}
Run Code Online (Sandbox Code Playgroud)
一切都工作正常,但突然之间,既不在代码baseform,也不 …
我有一个带有集成条形码扫描仪的 Android 设备。我按如下方式设置服务:
public class BarcodeService extends Service {
private final LocalBinder binder = new LocalBinder();
public class LocalBinder extends Binder {
public BarcodeService getService() {
return BarcodeService.this;
}
}
@Override
public IBinder onBind(Intent arg0) {
return binder;
}
@Override
public void onCreate() {
super.onCreate();
HandlerThread thread = new HandlerThread("ServiceStartArguments");
thread.start();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//Get scanner
}
}
Run Code Online (Sandbox Code Playgroud)
该服务也在AndroidManifest.xml. 使用此服务的类是:
public class BarcodeReader extends Activity {
private BarcodeService barcodeService;
private …Run Code Online (Sandbox Code Playgroud) 如果我有以下规则:
if (a == true && b == 0)
return errorsenum.somerror1;
else if (b < c)
return errorsenum.somerror2;
Run Code Online (Sandbox Code Playgroud)
如何将上述实现为FluentValidation规则?
编辑:
这两条规则有效吗?
RuleFor(x => x.b).GreaterThan(0).When(x => x.a);
RuleFor(x => x.b).GreaterThanOrEqualTo(x => x.c);
Run Code Online (Sandbox Code Playgroud) 有这样一个类:
public class MyRange
{
public int From {get; set;}
public int To {get; set;}
public MyRange(int from, int to)
{
From = from;
To = to;
}
}
Run Code Online (Sandbox Code Playgroud)
并具有List<MyRange>以下值:
var list = new List<MyRange>();
list.Add(new MyRange(1, 1000));
list.Add(new MyRange(1001, 2000));
list.Add(new MyRange(50, 1500));
list.Add(new MyRange(1900, 2900));
Run Code Online (Sandbox Code Playgroud)
是否可以有一个FluentValidation规则来检查上述范围不重叠?(范围之间的差距是有效的)
我有这些接口:
public interface _IService<T>
{
T Get(int id);
Task<T> SaveAsync(T entity);
Task<bool> DeleteAsync(int id);
}
public interface ICustomerService :
IService<Customer>
{
IEnumerable<Customer> GetMany(IEnumerable<int> ids);
}
Run Code Online (Sandbox Code Playgroud)
我还有一个抽象类和一个具体的类:
public abstract class Service : IDisposable
{
protected readonly IUnitOfWork unitOfWork;
protected Service(IUnitOfWork unitOfWork)
{
this.unitOfWork = unitOfWork;
}
public void Dispose()
{
if (unitOfWork != null)
{
unitOfWork.Dispose();
}
}
}
public class CustomerService : Service, ICustomerService
{
public CustomerService(IUnitOfWork unitOfWork)
: base(unitOfWork)
{ }
//Implementation here...
}
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.
现在我想添加通用工厂模式来实例化各种服务.所以我试着这样做:
public TService GetService<TService>() …Run Code Online (Sandbox Code Playgroud)