Unable to set TagBuilder InnerHtml Property to some value? - asp.net-core-3.1

I have noticed that TagBuilder InnerHtml Property has been changed in ASP.NET Core 3.1. It does not have
the set for InnerHtml property anymore. So when I try to do this:
TagBuilder tag = new TagBuilder("a");
tag.InnerHtml = "Hello";
I get the error as:
Property or indexer 'TagBuilder.InnerHtml' cannot be assigned to -- it is read only
I checked that in ASP.NET MVC the same code was working correctly. How to achieve -tag.InnerHtml = "Hello"; to work in asp.net core 3.1.

Related

How to properly Delete fields of an Entity?

I am having trouble when trying to delete a field of an Entity using Entity Framework (version 6.1.3).
Let's say I have two Entities: Person and Work.
I can change the work of a person without any issue, but when I try to express that the person is unemployed it does not work properly:
person.Work = null;
db.SaveChanges();
After running this code the person still will have the previous work, but if I use the debugger and check the Work property of person before running
person.Work = null;, everything will behave as expected.
Can someone please explain why reading the value first makes the code work properly and how to correctly delete the field?
var work = person.Work; \\ with this line here everything works as expected
person.Work = null;
db.SaveChanges();
Two things that are contributing to your issue:
Entity Framework determines what needs to updated during SaveChanges by tracking changes to property values.
You probably have lazy loading enabled (both in general and for the Work property), which means that if the person has an associated Work, that associated entity doesn't get loaded until the first time you access that property.
Putting those together, when you set person.Work = null without accessing person.Work (which would trigger a load), the context thinks nothing has changed. But if you load the property first, setting the property to null tells EF to remove that association. Edit: According to the page that octavioccl linked, this is true for .NET 4.0., but for .NET 4.5+ (and EF 5+), loading first is unneeded.
Possible solutions
If you want to remove the association without loading the related entity, you'll need to add a foreign key property to your Person entity, then you can set that to null instead of setting the navigation property to null. For example:
public class Person
{
// other properties...
public int? WorkId { get; set; }
public virtual Work { get; set; }
}
person.WorkId = null;
db.SaveChanges();
octavioccl's answer quoted another option:
context.Entry(person).Reference(p => p.Work).CurrentValue = null;
From this msdn page:
To delete the relationship, set the navigation property to null. If
you are working with the Entity Framework that is based on .NET 4.0,
then the related end needs to be loaded before you set it to null. For
example:
context.Entry(person).Reference(p => p.Work).Load();
person.Work = null;
Starting with the Entity Framework 5.0, that is based on .NET 4.5, you
can set the relationship to null without loading the related end. You
can also set the current value to null using the following method:
context.Entry(person).Reference(p => p.Work).CurrentValue = null;

Automatic Migrations Set Connection String in code .NET MVC

How to configure Entity Framework to use different connection string when executing migrations and when working with the database.
The reason for that is quite simple, I do not want to have sa login for the website, but I want to be able to execute migrations.
After not finding anything on the web for how to do that, the Object Explorer helped.
The EF Migration Configuration class (where AutomaticMigrationsEnabled = true is set)
has also a property named TargetDatabase.
This can be set to whatever connection string you want like so:
TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo(
ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString,
ConfigurationManager.ConnectionStrings["ConnString"].ProviderName);

Entity framework connection string reference from another project

I have a solution consisting of 4 projects. MVC, WCF, Business LYR, DataAcess. I am using entity framework for database transaction. My requirement is that i want to fetch the entity connectionstring only from MVC webconfig without refering in APP.cofig of acess layer. Is it possible in this scenario?
While I tried the following code I got an error.
this.ConnectionString="data source=cmh-sosql;initial catalog=Student;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework";
System.Data.SqlClient.SqlConnectionStringBuilder scsb = new System.Data.SqlClient.SqlConnectionStringBuilder(this.ConnectionString);
EntityConnectionStringBuilder ecb = new EntityConnectionStringBuilder();
ecb.Metadata = "res://*/schoolModel.csdl|res://*/schoolModel.ssdl|res://*/schoolModel.msl";
ecb.Provider = "System.Data.SqlClient";
ecb.ProviderConnectionString = scsb.ConnectionString;
using (SchoolDB schoolDB = new SchoolDB(ecb.ConnectionString))
Error: The entity type student is not part of the model for the current context.
You are absolutely correct. I got the solution. There is no need to keep any string in webconfig for reference to a entity model. We can use the above code for reference it. But the change is to configure the context object.
public SchoolDB(string connectionString)
: base(connectionString)
{
}
We need to change the constructor also by this format.
thanks Sampath

Property not found on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2

I am trying to create a with a list to choose from.
I am using JBoss 5.1 and Seam 2.2.
My list should be dynamically populated from my DB, but for the moment I am trying to create a simple list. Which is not working!!
My html:
<h:selectOneMenu>
<f:selectItems value="#{browseQuarters.qList}"></f:selectItems>
</h:selectOneMenu>
The bean has a "qList" member:
#In(required=false)
private List<SelectItem> qList = new ArrayList<SelectItem>();
Which has getters and setters:
public List<SelectItem> getqList(){
qList.add(new SelectItem(1,"one"));
return qList;
}
public void setqList(List<SelectItem> qList) {
this.qList = qList;
}
However, when I try running the page, I get this exception:
Property not found on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2
My project is generated using Jboss Tools, and I saw the other pages generated from the DB (to generate the entities) have a page.xml with the parameters defined..When creating this new form with New -> Seam form I only got a xhtml page and corresponding bean.
What's going wrong? I am of course a Seam/Java EE newbie, but have to do this ASAP :(
I think Seam/JSF will look for a method called getQList rather than the method you have, getqList. Try changing the names of the getter & setter.
Tip: Eclipse can generate compliant getters & setters for you.

Classic ASP: Server.CreateObject not supported

When I call Server.CreateObject(), from my Classic ASP page, I get
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method
I've tried the following (separately):
Server.CreateObject("Microsoft.XMLHTTP")
Server.CreateObject("MSXML2.XMLHTTP")
Server.CreateObject("MSXML.DOMDocument")
I know the ActiveX objects are installed because the following javascript calls work
var test = new ActiveXObject("Microsoft.XMLHTTP");
var test = new ActiveXObject("MSXML2.XMLHTTP");
var test = new ActiveXObject("MSXML.DOMDocument");
I'm calling it from my localhost IIS server. Any ideas how to troubleshoot this?
If you do the following:
Dim x: x = Server.CreateObject("My.ProgID.Here")
...VBScript creates the object and then attempts to access the default property for storing in 'x'. Since none of these objects have a default property defined (specifically an IDispatch-based property with [id(DISPID_VALUE)]), this fails with "Object doesn't support this property or method".
What you actually want is this:
Dim x: Set x = Server.CreateObject("My.ProgID.Here")
How about this one?
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
Or downloading this component and installing on your webserver?
http://www.microsoft.com/downloads/details.aspx?FamilyId=3144B72B-B4F2-46DA-B4B6-C5D7485F2B42&displaylang=en
Then restarting the server and trying again.
Calling them from the browser doesn't mean that they are installed in IIS.