小编Mit*_*áti的帖子

实体框架 - objectcontext处置异常

我一直在调试这个程序没有任何结果,不幸的是我无法看到问题的根源.我得到了这个异常:ObjectContext实例已被释放,不能再用于需要连接的操作.

有2个表: - CustomerSet - OrderSet

Orders表中名为Customer_id的字段可确保表之间的关系,并且Orders表中还有一个名为Customer的虚拟导航属性.

方案如下:我在Orders表中插入一个元素:

Order order = new Order();
Order.order_id = GenerateId(IdType.Order);
Order.date = DateTime.Now;
Order.Customer_id = GetCustomerId(tbCustomerName.Text);
Insert(order);
Run Code Online (Sandbox Code Playgroud)

在Insert方法中,在using语句中有DBContext,因此它在需要时自动处理.我在这里工作.

之后,我需要来自先前插入元素的数据(例如,我需要Customer字段的一些属性).现在我希望Customer领域有价值:

Order o = GetOrder(order.order_id);
Run Code Online (Sandbox Code Playgroud)

我在Customer字段中得到了一个例外:o.Customer抛出了'System.ObjectDisposedException'类型的异常

我正在玩懒惰的装载,打开或关闭它,但我没有锻炼.情况是一样的......

我该弄什么?

真正的好处在于,如果我一步一步地使用F11,它通常可以正常工作!

请帮忙!先感谢您.

c# frameworks entity objectdisposedexception objectcontext

6
推荐指数
1
解决办法
1万
查看次数

如何将sid和port包含在oracle连接字符串中?

我想在连接字符串中指定端口和sid.以下代码运行后

public static string ConnectionString
{
    get
    {
        string host = Config.CsHost;
        string sid = Config.CsSID;
        string port = Config.CsPort;
        string user = Config.CsUser;
        string pass = Config.CsPassword;
        return String.Format(@"Data Source = {0}:{1}\{2}; Persist Security Info = True; User Id = {3}; Password = {4}; Unicode = True", host, port, sid, user, pass);
    }
}
Run Code Online (Sandbox Code Playgroud)

...

using (OracleConnection connection = new OracleConnection(ConnectionString))
{
    try
    {
        connection.Open();
Run Code Online (Sandbox Code Playgroud)

Open()没有响应......问题在于我认为的sid.可能是什么问题?

更新:我应该使用这种连接字符串.但我不能很好地解释它.

数据源=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = MyHost)(PORT = MyPort)))(CONNECT_DATA =(SERVER = …

.net oracle connection-string

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

无法构建android项目,因为ActionBarActivity无法解析为某个类型

我正在关注developer.android.com网站上的培训,当我到达构建您的第一个应用程序/开始另一个活动部分时,我失败了:

我添加了android-support-v7-appcompat库,根据这个网站描述:http://developer.android.com/tools/support-library/setup.html#libs-with-res

我选择了android项目的库(项目的属性/ Android/Library)我单击了添加按钮,选择了项目库(第一张图片),然后在我按下确定之后项目没有构建.

之前(一切都好) 点击确定之前

不知何故,当我打开窗户时,它失败了.

在此之前...我以某种方式能够构建项目,按下播放,但不幸的是,它在启动后立即在我的设备上停止(崩溃).控制台说:

[2014-07-23 15:06:45 - android-support-v7-appcompat] Could not find android-support-v7-appcompat.apk!
Run Code Online (Sandbox Code Playgroud)

这就是我开始调查问题的时候......但是没有成功.

我的问题是,为什么在我再次检查后"停用"库?

java eclipse android android-support-library

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

如何用正则表达式替换匹配的组值

我想修改连接字符串中“数据源”组件的值。我正在考虑以下解决方案:

使用这个正则表达式模式:

"data source\=((\w|\-)+?\\{1}\w+?)\;"
Run Code Online (Sandbox Code Playgroud)

我可以获得以下字符串匹配:

Match.Groups[0].Value = "data source=MY-PC\SQLEXPRESS;"
Match.Groups[1].Value = "MY-PC\SQLEXPRES"
Run Code Online (Sandbox Code Playgroud)

因此,首先在连接字符串中,我想找到与“数据源=某事;”匹配的部分,其次仅替换连接字符串中的“某事”。怎么做?

.net c# regex connection-string

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

如何以编程方式添加更多样式设置器?当我尝试时,我得到一个InvalidOperationException异常(正在使用SetterBaseCollection)

我的App.xaml文件中有几个样式定义.像这样:

<Application x:Class="MyClient.App" ... >
    <Application.Resources>
        <SolidColorBrush x:Key="color1" Color="#FF7D7D" />
        <SolidColorBrush x:Key="color2" Color="#FF7D7E" />

        <Style x:Key="styleFor1" TargetType="charting:ColumnDataPoint">
            <Setter Property="Background" Value="{StaticResource color1}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:ColumnDataPoint">
                        <Grid>
                            <Rectangle>
                                <Rectangle.Fill>
                                    <LinearGradientBrush>
                                        <GradientStop Color="#ffff3737" Offset="0" />
                                        <GradientStop Color="#80000000" Offset="1" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <ToolTipService.ToolTip>
                                <StackPanel>
                                    <ContentControl Content="VALUES:" FontWeight="Bold" />
                                    <ContentControl Content="{TemplateBinding FormattedIndependentValue}" />
                                    <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                                </StackPanel>
                            </ToolTipService.ToolTip>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
Run Code Online (Sandbox Code Playgroud)

我生成一个图表.并给它的DataPointStyle:

Style dpStyle = Application.Current.Resources["styleFor1"]
Run Code Online (Sandbox Code Playgroud)

之后,我想在这个dpStyle中添加一些Setter.完成后我将图表的DataPointStyle设置为此dpStyle.然后我得到了例外.我该怎么办?请指导我.

更新:

异常详细信息(可能需要):

InvalidOperationException未处理

{"在'SetterBaseCollection'使用(密封)之后,它无法修改."}

TargetSite:{Void CheckSealed()}

c# wpf charts wpf-style

2
推荐指数
1
解决办法
1307
查看次数

我实现IEnumerator和IEnumerable的类不会转到foreach语句

我有一个存储字符串列表的类,我想让这个类在foreach语句中可用,所以我找到了这两个接口,我试图实现它们.

public class GroupCollection : IEnumerable, IEnumerator
{
    public List<string> Groups { get; set; }
    public int Count { get { return Groups.Count; } }
    int position = -1;
}

public IEnumerator GetEnumerator()
{
    return (IEnumerator)this;
}

public object Current
{
    get
    {
        try
        {
            return new Group(Groups[position]);
        }
        catch (IndexOutOfRangeException)
        {
            throw new InvalidOperationException();
        }
    }
}

public bool MoveNext()
{
    position++;
    return position < Groups.Count;
}

public void Reset()
{
    position = 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在迭代两次GroupCollection变量:

foreach (GroupCollection.Group in …
Run Code Online (Sandbox Code Playgroud)

.net c# ienumerable ienumerator foreach

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