小编Bab*_*loo的帖子

context.Entry()在哪里?

我通过阅读本文和许多其他文章编写了我自己的上下文,但没有一个主题解释了这个context.Entry(obj)定义的位置,我的意思是即使阅读本文,我也无法理解如何实现此方法,并且我得到以下错误:

错误36'Domain.Entities.OurWebSiteContext'不包含'Entry'的定义,并且没有扩展方法'Entry'可以找到接受类型为'Domain.Entities.OurWebSiteContext'的第一个参数(你是否缺少using指令或者装配参考?)

请有人帮帮我

编辑>>

 public class OurWebSiteContext : DbContext
    {
        public OurWebSiteContext(string connString)
            : base(connString)
        {

        }

        public DbSet<Article> Articles { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Comment> Comments { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

entity-framework

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

设置HttpContext.Current.User

我正在开发一个asp.net mvc 3.0应用程序,它具有简单的身份验证过程.用户填写一个通过ajax调用发送到服务器并获得响应的表单,但问题是使用以下方法:

FormsAuthentication.SetAuthCookie(person.LoginName,false);
Run Code Online (Sandbox Code Playgroud)

是不足以填充'HttpContext.Current.User',它需要运行以下方法:

FormsAuthentication.RedirectFromLoginPage("...");
Run Code Online (Sandbox Code Playgroud)

这里的问题是,正如我所提到的,loggin表单使用ajax表单,并使用json获取响应,因此无法重定向.

我怎么能填写'HttpContext.Current.User'?

谢谢.

更新:

这是注册方法:

 [HttpPost]
        public ActionResult Register(Person person)
        {
            var q = da.Persons.Where(x => x.LoginName == person.LoginName.ToLower()).FirstOrDefault();

            if (q != null)
            {
                ModelState.AddModelError("", "Username is repettive, try other one");

                return Json(new object[] { false, this.RenderPartialViewToString("RegisterControl", person) });
            }
            else
            {
                if (person.LoginName.ToLower() == "admin")
                {
                    person.IsAdmin = true;
                    person.IsActive = true;
                }

                da.Persons.Add(person);

                da.SaveChanges();

                FormsAuthentication.SetAuthCookie(person.LoginName,false);
return Json(new object[] { true, "You have registered successfully!" });

}

}
Run Code Online (Sandbox Code Playgroud)

authentication ajax asp.net-mvc-3

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

在datagridview列中替换true/false

我有一个datagridview,我填写如下:

var q= repository.GetStudents();//

dataGridView1.DataSource = null;
dataGridView1.Columns.Clear();

dataGridView1.DataSource = q;

dataGridView1.Columns.RemoveAt(1);
//Remove IsActive 
//Cause I want to have my own implementation 

dataGridView1.Columns[0].DataPropertyName = "StudentID";
dataGridView1.Columns[0].HeaderText = "Studunet ID";

dataGridView1.Columns[1].DataPropertyName = "IsActive";
dataGridView1.Columns[1].HeaderText = "Status";
Run Code Online (Sandbox Code Playgroud)

"IsActive"属性是布尔类型.当显示"IsActive"单元格时,它显示true/false.我想用我自己的自定义值替换它.

我读这个这个职位,但我解决不了我的问题.

c# datagridview winforms

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

在layout-land中定义的xml布局没有出现在android应用程序中

我正在根据这个例子开发一个应用程序.我在layout-land文件夹中为header.xml定义了横向布局,但是当我将方向更改为横向时,定义的布局不会出现在屏幕中.

知道为什么吗?

谢谢

更新 :

活动代码:

public class ACENewsFeedActivity extends ListActivity {

    // Progress Dialog
    private ProgressDialog pDialog;

    // Array list for list view
    ArrayList<HashMap<String, String>> rssItemList = new ArrayList<HashMap<String,String>>();

    RSSParser rssParser = new RSSParser();

    List<RSSItem> rssItems = new ArrayList<RSSItem>();

    RssFeed rssFeed;

    private static String TAG_TITLE = "title";
    private static String TAG_LINK = "link";
    private static String TAG_DESRIPTION = "description";
    private static String TAG_PUB_DATE = "pubDate";
    //private static String TAG_GUID = "guid"; // not used

    /** Called when …
Run Code Online (Sandbox Code Playgroud)

android android-layout

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

在Windows 8应用程序中为DispatcherTimer的Tick事件定义事件处理程序

我正在Windows 8 Visual Studio 11中开发一个应用程序,我想为DispatcherTimer实例定义一个事件处理程序,如下所示:

public sealed partial class BlankPage : Page
    {

        int timecounter = 10;
        DispatcherTimer timer = new DispatcherTimer();
        public BlankPage()
        {
            this.InitializeComponent();
            timer.Tick += new EventHandler(HandleTick);
        }

        private void HandleTick(object s,EventArgs e)
        {

            timecounter--;
            if (timecounter ==0)
            {
                //disable all buttons here
            }
        }
        .....
}
Run Code Online (Sandbox Code Playgroud)

但是我得到以下错误:

Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>'
Run Code Online (Sandbox Code Playgroud)

我是widows 8应用程序的新手开发者.

你能帮帮我吗?

windows-8

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

google map api v2,以及旧版本的google play services lib

我将在我的Android应用程序中使用地图,我应该使用谷歌播放服务.我阅读了大量的Q \这里一个像这样.在上面提到的问题中,接受的答案建议使用旧版本的google play服务lib,就像Froyo那样.我下载了谷歌播放服务r10并在我的应用程序中使用它,但我收到了错误.

如果我从清单中排除这行代码:

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
Run Code Online (Sandbox Code Playgroud)

并在我的设备中运行应用程序(我的设备中当前版本的google playe服务是3.2.66),它会抛出错误:

java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Run Code Online (Sandbox Code Playgroud)

如果我用android:value = 4030500包含它,该应用程序运行,但说我应该更新我的"谷歌播放服务".

那么我应该把android:value或者我的方法完全正确呢?

问候

android google-maps google-play

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

该模块要求HttpApplication实现IContainerProviderAccessor

嗨我想在我的asp.net mvc appliation中使用Autofac,这是我在global.asxc文件中的代码:

 protected void Application_Start()
    {
        ....

        var builder = new ContainerBuilder();
        builder.RegisterControllers(Assembly.GetExecutingAssembly());

        IContainer container = builder.Build();

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    }
Run Code Online (Sandbox Code Playgroud)

但是当我运行项目时,我看到了这个错误:

该模块要求HttpApplication(全局应用程序类)实现IContainerProviderAccessor

怎么了 ?

asp.net-mvc autofac

4
推荐指数
2
解决办法
4983
查看次数

通过使用良好的状态空间然后搜索树来解决河内塔

我想用一个好的"国家空间"解决"河内塔"的问题.使用适当的状态空间是一些AI技术所建议的方式.拥有一个良好的状态空间,我希望能够构建一个搜索树,然后使用一些策略,如"DFS"(深度优先搜索)来找到解决方案.

我的问题是,我只是不知道如何开发一个好的状态空间然后用它来构建一个搜索树.任何人都可以描述如何为河内塔问题创建一个州空间吗?然后告诉我如何为此构建搜索树?

artificial-intelligence towers-of-hanoi

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

MVC 3和MEF以及向主应用程序添加插件

我是MEF的新手,我真的很混乱!这里有很多有用的文章,在stackoverflow中有很多问题和答案.我下载了@ matthew-abbott在他的博客中上传的示例,但我不知道如何添加新的插件或扩展来扩展主Web应用程序,我的意思就像你在这里看到的那样.

编辑:我也使用实体框架,代码优先方法和工作单元为我的数据访问层应用程序,如果我的插件需要数据访问和(我的意思是插件本身模型)想要使用我创建的DAL ?正如您所知,每次模型更改时,DbContext都会抛出错误并告诉重新创建数据库,是否有任何方式或其他ORM动态接受扩展DAL?

mef entity-framework-4 asp.net-mvc-3

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

Autofac,Owin,Webapi和注入AuthorizationServerProvider

在阅读有关使用owin和webapi的autofac的问题和文章后,我遇到了注入服务的解决方案,但它不起作用.这是我的代码:

public class StartUp
{
    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        WebApiConfig.Register(config);

        var builder = new ContainerBuilder();                                    // Create the container builder.
        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());         // Register the Web API controllers.

        var authcontext = new AuthContext();

        builder.RegisterInstance(authcontext).AsSelf().SingleInstance();

        //Updated
        //var simpleauth = new SimpleAuthorizationServerProvider();
        //Updated
        // builder.RegisterInstance(simpleauth).SingleInstance().AsSelf().PropertiesAutowired();

        builder.Register(x => new UserStore<IdentityUser>(authcontext)).As<IUserStore<IdentityUser>>();

        //updated

        builder.Register(x =>
        {
            var p = new SimpleAuthorizationServerProvider();
            var userStore = x.Resolve<IUserStore<IdentityUser>>();
            p.userManager = new UserManager<IdentityUser>(userStore);
            return p;
        }).AsSelf().PropertiesAutowired();

        builder.RegisterType<AuthRepository>().As<IAuthRepository>().InstancePerRequest().PropertiesAutowired();

        var container = builder.Build();

        var resolver = …
Run Code Online (Sandbox Code Playgroud)

autofac asp.net-web-api owin

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